Why do you need to fry onions and garlic before adding other ingredients to a dish? I've been using an online Paella recipe that instructs you to sweat some onions for 5 minutes, then add garlic for a few minutes, followed by the vegetables, tomatoes, rice and stock.

Is there a reason the onions need to be added and fried first (and before the garlic)? Does it affect the taste at all?

Recipe was Saffron Seafood Paella
It's not so much the taste as the texture. If they haven't been sauted first, the onions stay relatively crunchy during the rest of the cooking. The same is true of the garlic, but you'd usually have cut the garlic into much smaller pieces so it doesn't take as long to soften up, hence kicking the onion off first and adding the garlic a bit later.