- Home /
Start being called after Update of another GameObject?
I've got a very very weird scenario...
I've got two GameObjects - parent and child. Each one has its own script. The parent has an Update()
method, while the child has a Start()
. The parent prefab is instantiated from a Start()
method of a third object (separate object hierarchy).
Now the first time the level is loaded, the parent is instantiated fine with it's child, and all works as expected. Then I load another level, and reload this level again. This time, when I load the level, the parent object is instantiated fine, but for some reason, the Update()
of the parent object is called before the Start()
of the child object. I figured this is very weird since they are both instantiated at the same time, so I'd expect the Start()
calls to happen before the Update()
calls...
Can anyone explain? Is this a bug?
I'd note that I couldn't get this to reproduce in a minimal project, and my project is kinda large already... But for sure this is the only place where these scripts are attached.
Update:
I changed the Start()
to Awake()
and it works fine now, always calls the Awake()
before any other Update()
. Unity bug?
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. See: http://docs.unity3d.com/Documentation/Components/class-ScriptExecution.html
Yeah, but I'm talking about an Update()
being called before Start()
... And according to the $$anonymous$$onoBehaviour.Start() documentation:
Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
So I'd expect the Start()
to be called before Update()
regardless of the script execution order.
Your answer
Follow this Question
Related Questions
Update and Awake not being called. 1 Answer
how to call something just once from an update function 5 Answers
Start() not called upon instantation? 1 Answer
Start, Awake, Update. Any other ways to call functions from an empty GameObject? 3 Answers
My randomly generated slope game doesn't seem to work? 0 Answers