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

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.

Did you find any workaround ? I’m having this specific issue as well and I’d like to better my current workflow

My workaround is and has always been to NEVER place anything in any scene anywhere that ANYONE outside needs to access.

So if you’re making a common “thing” and a lot of different things are gonna need it, NEVER place it in a scene. NEVER.

Instead, make the thing a prefab and then demand-load it as soon as anyone attempts to access it. This can apply to Game managers, Level / Wave managers, enemy managers, UI / Menu managers, Music managers, pretty much anything.

This has the side benefit of “keeping you honest” and not making your scenes a morass of entangled references.

Here’s the super-simple sauce to make that happen, either with our without predefined data:

Simple Singleton (UnitySingleton):

Some super-simple Singleton examples to take and modify:

Simple Unity3D Singleton (no predefined data):

https://gist.github.com/kurtdekker/775bb97614047072f7004d6fb9ccce30

Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:

https://gist.github.com/kurtdekker/2f07be6f6a844cf82110fc42a774a625

These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance