The first thing I want to do it on Awake is trying to load some data. If that load fails, I want to present a window to the user in which he can chose to try again or to quit application. I need to PREVENT the Awake to continue its execution (and the Start()) because I do stuff with that data. I don’t think and IF is the solution.
Im guessing I need to use a coroutine there, but Im failing to do it. I have something like:
void Awake()
{
StartCoroutine(GetData());
Debug.Log("Dont display until got data");
}
Any Idea?
Your desire is clear, but your method is questionable. You can do what you’re describing, but your program will hang (appear non-responsive) until the loading method is complete. The best practice is to distribute expensive operations over multiple frames. Even if the user cannot click or interact, at least their PC will respond properly. Many software vendors reject projects that hang in this fashion.
Consider simply moving the remainder of your Awake() logic to the end of the expensive coroutine (or a method called at the end), and ensure the coroutine has WaitFor statements to prevent hangs.
Awake and Start are convenient in a lot of cases, but you shouldn’t rely on them for enforcing order-of-execution throughout your project. There are better ways (manual initialization is often a must)