Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Execution Start Order

Discussion in 'Scripting' started by davej256, Nov 25, 2022.

  1. davej256

    davej256

    Joined:
    Nov 11, 2022
    Posts:
    16
    Suppose I have 100 different GameObjects in my scene. They all share the same script. If I compile a build and share it with 10 friends, will those scripts start in the same exact order on all of their machines?

    What about a server and client build?
     
  2. olejuer

    olejuer

    Joined:
    Dec 1, 2014
    Posts:
    210
    No, and you can find the answer in the manual.
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
    "[...] The order that Unity calls each GameObject's Awake is not deterministic[...]"

    Use an initialization script that references your objects in a list or array and have it call some Init() method sequentially, if you really need that.

    You should, however, think again whether you can find a better design that does not rely on the order of those calls.
     
    Bunny83 likes this.