- Home /
About Update Order in child and parent question
Update() maybe called at "random" order. But if a gameobject is a other gameobject's child,is the Update order predicable?
First called update in all children and then called update in their parent as the same as Start()?
Very thanks!
Answer by aldonaletto · Dec 05, 2011 at 11:29 PM
Don't bet your life on this: I created a simple test script and attached it to several objects. They seemed to follow the "women and children first" rule, but things changed when I added two new children to the parent: another "external" object entered the order, messing things up. The script I added to the objects is:
static var updateOrder = 0; var order = 0;
function Update(){ order = ++updateOrder; }
function LateUpdate(){ updateOrder = 0; } I just watched the order variable of each object in the Inspector to learn the sequence its Update was called.
You can define scripts execution order in Unity 3.4: select the script in the Project view and click the Execution Order button in the Inspector.
I honestly don't know how multiple instances of the same script are ordered, but hope this may help solving your problem.
There is no specific order. Only the script execution order in Unity 3.4 (like you've mentioned). GameObjects don't have a hierarchical order, just their transform components have. From Unity's view it have a list of GameObjects which might be ordered the same way they have been created, but you can't deter$$anonymous$$e that at runtime.
If you need an exact order just implement your own message chain. For example with Broadcast$$anonymous$$essage. I'm not a fan of Broadcast$$anonymous$$essage so i would use some kind of interface i can use. It depends on whether the childs are created / removed dynamically or if you have a static hierarchy. For a static hierarchy it's the easiest to hold a list with all child scripts which you can process in the order you like.
Your answer
![](https://koobas.hobune.stream/wayback/20220613061811im_/https://answers.unity.com/themes/thub/images/avi.jpg)