Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question ELI5 multiple / additive scenes..

Discussion in 'Editor & General Support' started by DrMeatball, Jan 10, 2024.

  1. DrMeatball


    Nov 21, 2021
    I thought I understood how / when to use additive scenes but I'm having trouble implementing which makes me think I don't understand after all.

    Every time I restart Unity, I lose all of my added scenes from my main Game scene. Why?

    Screenshot 2024-01-10 032241.png

    I have been using Additive Scenes to make my organization and project management better. I've been doing everything in separate scenes (lighting, logic, character / player, enemies, levels, puzzles, etc etc) for my world building and then adding them all to my main Game scene. Is this wrong?

    I've already gone through this.. Unity - Manual: Work with multiple scenes in Unity ( really doesn't tell my much of anything useful.
  2. arkano22


    Sep 20, 2012
    You can't add scenes to the main Game scene (or any other scene, for that matter). There's no such thing as scene nesting in Unity, so this doesn't make any sense.

    Each scene is still completely independent from each other. You can load and edit multiple scenes at the same time in the editor, but that's all. So when you restart the editor, only one scene is opened.

    Additive scenes are meant to be loaded at runtime. You edit your scenes in the editor, then you load them all additively using LoadSceneMode.Additive. You should prepare a LightingScene, a LogicScene, a EnemiesScene, etc. then load them all at runtime when needed.

    From the manual:

    Last edited: Jan 10, 2024
    DrMeatball likes this.
  3. Kurt-Dekker


    Mar 16, 2013
    Here's a bit more reading on the subject... it can take a while to sorta wrap your head around:

    Additive scene loading is one possible solution:

    A multi-scene loader thingy:

    My typical Scene Loader:

    Other notes on additive scene loading:

    Timing of scene loading:

    Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It's a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

    Two similar examples of checking if everything is ready to go:
  4. flashframe


    Feb 10, 2015
    Just to add - you CAN save and load "Scene Setups" to make working with multi-scene workflow more tolerable in the editor. (e.g. if you want some scenes to always be opened together when working in the editor). You just have to write some custom code to get it working.

    You can store SceneSetups in scriptable objects in your project:

    Code (CSharp):
    1. public class SceneCollection : ScriptableObject
    2. {
    3.     public SceneSetup[] setup;
    5.     public void SaveSetup()
    6.     {
    7.         setup = EditorSceneManager.GetSceneManagerSetup();
    8.     }
    10.     public void LoadSetup()
    11.     {
    12.         if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
    13.         {
    14.             EditorSceneManager.RestoreSceneManagerSetup(setup);
    15.         }
    16.     }
    17. }
    I have a custom editor window that is registered for the "sceneOpened" event in the EditorSceneManager to auto restore a setup when a scene is opened in the editor

    Code (CSharp):
    2. private string lastActiveScene;
    4. private void OnSceneOpened(Scene scene, OpenSceneMode mode)
    5. {
    6.     if (mode == OpenSceneMode.Additive) return;
    7.     if (SceneManager.GetActiveScene() != scene) return;
    8.     if (string.Equals(lastActiveScene, scene.path)) return;
    10.     lastActiveScene = scene.path;
    12.     if (sceneCollections == null || sceneCollections.Count == 0) return;
    14.     foreach (SceneCollection sc in sceneCollections)
    15.     {
    16.         if (sc.setup == null || sc.setup.Length <= 0) continue;
    18.         foreach (SceneSetup setup in sc.setup)
    19.         {
    20.             if (!setup.isActive) continue;
    21.             if (string.Equals(setup.path, scene.path))
    22.             {
    23.                 Debug.Log("Restoring" + + " Scene Setup", sc);
    24.                 sc.LoadSetup();
    25.                 return;
    26.             }
    27.         }
    28.     }
    29. }
    Last edited: Jan 10, 2024