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

    DrMeatball

    Joined:
    Nov 21, 2021
    Posts:
    116
    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 (unity3d.com).. really doesn't tell my much of anything useful.
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    2,034
    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:
    https://docs.unity3d.com/2020.1/Documentation/Manual/MultiSceneEditing.html

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

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,412
    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:

    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6630961
    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6754330

    https://forum.unity.com/threads/problem-with-canvas-ui-prefabs.1039075/#post-6726169

    A multi-scene loader thingy:

    https://pastebin.com/Vecczt5Q

    My typical Scene Loader:

    https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

    Other notes on additive scene loading:

    https://forum.unity.com/threads/removing-duplicates-on-load-scene.956568/#post-6233406

    Timing of scene loading:

    https://forum.unity.com/threads/fun...ject-in-the-second-scene.993141/#post-6449718

    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:

    https://forum.unity.com/threads/daily-events-and-content-changes.1108202/#post-7143713

    https://forum.unity.com/threads/uni...on-before-other-scripts.1153739/#post-7401794
     
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    819
    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.

    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneSetup.html

    https://docs.unity3d.com/ScriptRefe...torSceneManager.RestoreSceneManagerSetup.html

    You can store SceneSetups in scriptable objects in your project:

    Code (CSharp):
    1. public class SceneCollection : ScriptableObject
    2. {
    3.     public SceneSetup[] setup;
    4.  
    5.     public void SaveSetup()
    6.     {
    7.         setup = EditorSceneManager.GetSceneManagerSetup();
    8.     }
    9.  
    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

    https://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager-sceneOpened.html

    Code (CSharp):
    1.  
    2. private string lastActiveScene;
    3.  
    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;
    9.  
    10.     lastActiveScene = scene.path;
    11.  
    12.     if (sceneCollections == null || sceneCollections.Count == 0) return;
    13.  
    14.     foreach (SceneCollection sc in sceneCollections)
    15.     {
    16.         if (sc.setup == null || sc.setup.Length <= 0) continue;
    17.  
    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" + sc.name + " Scene Setup", sc);
    24.                 sc.LoadSetup();
    25.                 return;
    26.             }
    27.         }
    28.     }
    29. }
     
    Last edited: Jan 10, 2024