- Home /
Execution order of multiple scripts attached to different GameObjects
Hey guys....
I've read the unity docs and i can say i underestand the execution flow when it comes to only one script. However,what happens when we have two or more scripts attached to different gameobjects that run in parallel?
I was wondering if unity is using some kind of time sharing when executing multiple scripts.For example Script 1 runs for 2secs (just an example) then Script 2 resumes its execution for another 2 seconds and so on....
If something like that happens,is it a possible that a function executing in one script gets interrupted before it completes for another script to run?Or function calls are "atomic"?
Thank you in advance?
Answer by ScroodgeM · Aug 30, 2012 at 08:09 PM
http://docs.unity3d.com/Documentation/Manual/ExecutionOrder.html
http://docs.unity3d.com/Documentation/Components/class-ScriptExecution.html
if you still have questions, just ask 8)
Thank you. So may i suppose that if we have two scripts,the execution sequence is something like that? a)Script 1 Awake function b)Script 2 Awake function c)Script 1 Start function d)Script 2 Start function e)Script 1 Physics etc... f)Script 2 Physics etc.. and so on ?
all Awakes are called first once, then, all Starts once.
after that, each frame are called all Updates, and every fixed time step are called FixedUpdates. between similar methods ScriptExecutionOrder by script type can be used to sort in order you need
Thank you very much for clearing things up! Of course i accepted your answer!