- Home /
To use or not to use script execution order
I'm just wondering if this feature is widely used by the pro devs. I mean, is this really what we should use to make sure a script is executed first before the other or should I just make function calls/init functions then call then manually when certain conditions are met.
I have this object pooling class. And I have to make sure that all the objects are created first before I get something on the pool. It returns an error(bec some of my script runs first before this object pool class) unless I use this Script Execution order thing. In as3 we have this document class where you control the order of the class to be executed. Is this feature the equivalent of that in unity, what about in C#(outside unity) where I'm not sure if this feature is available how would you normally control code execution order?
I'll also appreciate suggestions for a more robust way of script execution order.
It seems to me that Execution Order matters most when you are pushing floating value changes to scripts at the wrong time. (They are floating as you are unsure whether the change has been made on the current script execution).
It seems far more reliable to retrieve values from a script ins$$anonymous$$d. It appears to cut out most need for Execution Order.
The root-causes not dealt with by the above are usually avoided with the odd yield here and there.
I would use 'script execution order' as my last resource. It doesn't make sense if you use it for quick-hacks.
Outside Unity, Awake()
and Start()
don't get called, because outside Unity $$anonymous$$onoBehaviour
is not defined. So script execution order is purely a Unity thing. It's the answer to a traditional game loop when you need specific script run order but haven't connected them together yourself.
This is useful when writing plugins and modular code, as you don't/can't know how specific game does its logic. But you still want a proper execution order.
Of course, the more I work with it, the less I like it. Once your game goes past a certain complexity, execution order becomes another hack. (Also, yield and co-routines in never an answer, in my opinion.)
I've had a simulair question. Just use it. If pro's use it or not as long as it works. It wont affect peformance aswell so you should really be bothered
Answer by GameVortex · Nov 28, 2014 at 11:57 AM
If it solves your problem then use it, but in almost all cases it can be solved better by smart use of the Awake and Start functions. If that is not possible then using a manager to initialize the objects in the correct order works as well.
In your situation you should probably create all the objects in the pooling manager Awake function and not use it until the Start function of any the object that wants to use the pooling manager.
thanks for all the input guys. I'll try to make a smart use of the awake and Start first. then ill use this feature if laziness takes over. but this feature really seems incredibly useful!
Your answer
Follow this Question
Related Questions
Script Execution Order library 1 Answer
Order of Update(), Awake(), etc of gameobjects and their child gameobjects 1 Answer
Script Execution Order removes scripts on apply 1 Answer
Manage the script execution order, how? 1 Answer
Two monobehaviour scripts attach to one gameobject and the Update order predicable? 3 Answers