How to prevent the cake-y look

I use Mac foundation and sometimes it turns out cake-y looking. I use foundation, concealer and setting powder. It doesn’t happen every single time, but how do you prevent it?