[5.3+] Persisting a Manager Scene Using SceneManager

I’ve found myself in an interesting grey area with scene loading since I upgraded into the 5.3s.

Docs recommend:

“It is recommended to avoid using DontDestroyOnLoad to persist manager GameObjects that you want to survive across scene loads. Instead, create a manager scene that has all your managers and use SceneManager.LoadScene(, LoadSceneMode.Additive) and SceneManager.UnloadScene to manage your game progress.” (Unity - Manual: Work with multiple scenes in Unity in Tips and Tricks)

Since I had been using lots of DontDestroyOnLoad, I listened to this and converted to a Manager scene.

Then, I went and updated my scene loading scripts to use SceneManager rather than the newly-deprecated methods (Note, I am using LoadSceneAsync). I see three ways I can implement this, and none is ideal:

  • Don’t persist gameobjects by using LoadSceneMode.Single when moving between major scenes, then have the new scene load in my Manager scene additively each time. Since my Manager doesn’t persist, it’s scripts also get reset each time causing all kinds of problems (a simple example: music script stops playing or restarts from beginning of song). (Unacceptable.)

  • Persist gameobjects by going back to DontDestroyOnLoad, getting rid of the Manager scene altogether, and going against documentation recommendations. (Maybe ideal?)

  • Persist gameobjects by loading a new scene additively, leaving Manager untouched. Here we branch, with both options throwing up anger in the console:

  • Either I unload the current scene before finishing the next, causing a brief lack of audio listeners and a camera-less blank screen. (Unacceptable.)

  • Or, I unload the current scene after finishing the next, causing multiple audio listeners and multiple EventSystems to exist at once. (My current implementation)

So, here’s my question: how can I persist a Manager scene between scene changes without using DontDestroyOnLoad or accidentally having multiple major scenes loaded at the same time, if briefly?

2 Likes

I would suggest moving the EventSystem, Audio and Camera(s) to the persistent Manager scene. This will prevent multiple occurrences of these objects while offering complete control during scene changes. Possibly these objects should be in separate persistent Manager scenes to specialize in handling different aspects of the project.

With regards to scene transition:

  • Loading Level Scene - When switching between two large scenes, it is possible to use a “Loading Level” scene. This is a tiny scene that can be loaded (additively) to the most recent large scene. While, the tiny “Loading Level” scene is distracting the user (with game tips, game status, etc.) the old large scene is unloaded and the next large scene is loaded (additively). Here’s an example of one implementation.

  • Smaller Level Scenes - I believe that this is the intended direction of the technology. Rather than have an entire level in one scene, the level should be modularized into smaller parts. In that manner, it should be possible to:

  • start with scene Level1A

  • load scene Level 1B (additively)

  • unload scene Level1A
    repeat…

  • load scene Level 2A (additively)

  • unload scene Level1x
    so loading levels become seamless

Here’s an example where a level is progressively built.

3 Likes