Unity is ignoring script execution order.

As in the title.

I have an A and a B.

I need A.Start() called before B.Start().

I have them arranged accordingly in MonoManager.

The ordering imposed on A and B for any function (Update(), FixedUpdate(), OnGUI(), etc…) is not respected at runtime.

What do?

I just had the same problem, i.e., I set the execution order (Edit → Project Settings → Script Execution Order) to “first A then B”, but the Start() method was executed in order “first B then A”.

I then had a look at the Unity manual for Script Execution Order Settings and there it says:

By default, the Awake, OnEnable and Update functions of different scripts are called in the order the scripts are loaded (which is arbitrary). However, it is possible to modify this order using the Script Execution Order settings (menu: Edit > Project Settings > Script Execution Order).

So, it only mentions Awake, OnEnable, and Update, but not Start. And that’s obviously what’s happening (not that I understand why they didn’t include Start in the execution ordering).

Script execution order does work, but there are a few priorities before that, among each method… Maybe you weren’t accounting for that, or it might be broken in some way I’m not aware.

In any case, you can also roll your own Start manager, as mweldon already mentioned. Simply create a script with an Start which will be the only one with such method and will call other custom made methods in any other script in the order you need.

“The ordering imposed on A and B for any function (Update(), FixedUpdate(), OnGUI(), etc…) is not respected at runtime.”

You answered your own question. Unity does not guarantee that objects will be processed in any particular order. If you have to guarantee order, then you have to do it manually.

I try to put all local initialization in Awake, then anything that requires references to other objects in Start. This fixes some, but not all of my order problems.

If you have a situation that is order dependent, then you will need to create your own update function (I like to call it MyUpdate) for the order-dependent objects and call them manually in the order you need.

Hey, you can use Awake() instead of Start() in one of your scripts. This should make one being initialized later than another one.