Unity Ignores Script Execution Order


my environ :
unity 3.5
Android(galaxy s4)
pc (i5-750, ddr3 16g)

i making android game project with Unity3d.
but i can’t solving this problem, finally i reached next : Unity Ignores Script Execution Order

GameObject ‘Block’ is a Prefab, and managed customized pooling.
it have script scBlock.cs and scObjectPool.cs and many Others. (every script is monobehaviour script)
(and i know the pooling is very complicated of using start() or awake() because i using pooling)

problem :
I want scObjectPool.Awake is called before scBlock.cs
but I Logged it, It always scBlock.Awake() is first. (and next log is scObjectPool.Awake)
(and i think my log can’t be wrong. cuz my log position is first line of each component’s Awake() function’s)

i tried to using scBlock.OnEnable because script running order is Awake->OnEnable->Start…

but scBlock.OnEnable is called first of scObjectPool.Awake
the order is scBlock.AwakescBlock.OnEnablescObjectPool.Awake

so i tried to using Edit->Project Settings->Script Execution Order
And make scObjectPool’s order -3 (upper than Default Time… and scBlock’s order is Default Time)

but result is same. the order is scBlock.AwakescBlock.OnEnablescObjectPool.Awake

and i tried to make scObjectPool’s order -3, and scBlock’s order -2. …

but result is same! the order is scBlock.AwakescBlock.OnEnablescObjectPool.Awake!

this result say to me “the unity ignores script execution ordering!”

who knows why this problem happens?
it is just a bug? (unity 3.5.5f)
or script execution order is following Prefab inspector’s showing order?

And i finally bypass problem, but if i can’t know the problem’s origin, the problem bothering me after all. please someone help me!

Personally, I don’t use and depend on execution order.

You should do your own “ready check” for the prioritized script in the other scripts.

For example, you have a MapGenerator script which creates the cells of the 2D map array, and you have ArmyGenerator script which creates the army units on the generated map cells.

Obviously, ArmyGenerator should run after MapGenerator completes its job.

So you can implement a variable in MapGenerator named “Ready” and set it true after the job is done… then you can make ArmyGenerator to wait until MapGenerator.Ready is true.

This is the best logic for me in Unity environment.

Script execution order is generally used to prioritize the update events, not the startup events. I still prefer to implement a similar method to prioritize the update events instead of using execution order method.