Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Feedback Could the order of scene loading in the editor be made deterministic?

Discussion in 'Editor & General Support' started by Xarbrough, Feb 9, 2021.

  1. Xarbrough


    Dec 11, 2014
    The community agrees that it's a bad thing to depend on the order of callbacks like Start or OnEnable being called in a specific order when multiple scenes are involved. To solve this issue at runtime, it's possible and common to start from a single boot scene and then load scenes deterministically in user code. For example, I could ensure that my UI scene is always loaded before the next gameplay level. Such an approach works fine and without too many side effects at runtime.

    In the editor, however, this approach requires compromises or editor tool scaffolding to make it work. For example, users could be forced to always start in the boot scene before testing. Or an editor script can automatically load scenes in a specific order. However, this is not always possible. Consider the following example:

    Scenes A and B are loaded in the editor. B is the active scene. My custom scene loading code would normally enforce the scenes to be loaded in the order A and then B. But if I press play, Unity will load scene B first, call Awake, then load Scene A.

    To work around this I could try to implement RuntimeInitializeOnLoadMethod before scene load. However, now I cannot detect if a scene is currently loading, so it causes all sorts of difficult to manage conflicts.

    I propose that Unity makes the loading of scenes in the order deterministic by loading them in the order they appear in the hierarchy. This would at least make it possible to configure the editor to behave the same way typical runtime code is structured without jumping through hoops.