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?
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?
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.
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:
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:
public class SceneCollection : ScriptableObject
{
public SceneSetup[] setup;
public void SaveSetup()
{
setup = EditorSceneManager.GetSceneManagerSetup();
}
public void LoadSetup()
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
EditorSceneManager.RestoreSceneManagerSetup(setup);
}
}
}
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
private string lastActiveScene;
private void OnSceneOpened(Scene scene, OpenSceneMode mode)
{
if (mode == OpenSceneMode.Additive) return;
if (SceneManager.GetActiveScene() != scene) return;
if (string.Equals(lastActiveScene, scene.path)) return;
lastActiveScene = scene.path;
if (sceneCollections == null || sceneCollections.Count == 0) return;
foreach (SceneCollection sc in sceneCollections)
{
if (sc.setup == null || sc.setup.Length <= 0) continue;
foreach (SceneSetup setup in sc.setup)
{
if (!setup.isActive) continue;
if (string.Equals(setup.path, scene.path))
{
Debug.Log("Restoring" + sc.name + " Scene Setup", sc);
sc.LoadSetup();
return;
}
}
}
}