How does Awake() work in scripts relative to one another's Awake() methods?

This is a question that I’ve thought about for a while and could not find an answer to. Given five objects with five scripts attached, each with an Awake() method, which Awake() gets called first? If they get called simultaneously (is this even possible without multithreading?), how are the code lines executed and in what order considering that there are five Awake methods? (This question applies to Start() as well.)

they’re called in whatever order the engine decides to.

This is why there is Awake and Start, not just one. All the Awakes are called (in whatever order), once all Awakes are complete all the Starts are called (in whatever order).

Awake is used to setup the “internal” references which are not dependant on anything other than the current gameobject. Start can then be used to setup references to other gameobjects/components safe in the knowledge that whatever Awake function logic has been completed.

1 Like

By default the order is pretty arbitrary, but you can define Execution order per class but not per object in the editor.

You should not be trying to access other scripts in the Awake Message, but use Awake to setup stuff internal to your script, or using builtin components. Then use Start to do stuff between scripts.

1 Like

Thank you for the explanation. I know about the execution order and have that bookmarked - it doesn’t answer this question, though, but I think that you did.

This is good to know, thanks!