Problems with the order that various script Awake() etc functions are called

I am starting to notice that the order in which Awake and Start functions are called is unpredictable (or it seems so).

If you have the initialization of one object dependent on the initialization of another then you can start running into problems with null object exceptions.

Are there any recommended ways of managing this if such dependencies are necessary?

Also, when folks say you shouldn’t call GameObject.Find(…) in Update(), does that mean not even if Find is called as a result of user input for example?

If so would there be any benefits to be gained by creating your own map of game objects and implementing your own Find function?

So the events themselves for a specific object are called in a specific order:

But the order between objects is in the order they were loaded. So there’s no guarantee that ‘Awake’ was called on one object, before or after, another object.

This is why they say use ‘Awake’ to configure the self. And ‘Start’ to communicate between objects.

If you need greater control over ordering when scripts execute relative to one another, you can also forcibly control when scripts execute relative to each other:

This is especially useful if your script needs to configure in Awake, because it may or may not be enabled immediately (Start won’t occur until just before the first Update after being enabled).

1 Like

Oh the perils of the visual programming paradigm.

Here is a working link for what was offered above: