Loading lessons...
Multi-Scene Editing
Multi-Scene Editing
Multi-scene editing allows you to open, edit, and run multiple scenes simultaneously in the editor and at runtime.
Benefits
- Persistent Managers: Keep one scene loaded with managers, audio controllers, and UI, while swaping level scenes.
- Team Collaboration: Different developers can work on separate scenes of a single level without conflict.
- Large World Streaming: Load and unload level chunks dynamically as the player moves.
Loading Scenes Additively
By default, loading a scene closes all currently loaded scenes. Use LoadSceneMode.Additive to load scenes concurrently:
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneManagerHelper : MonoBehaviour
{
public void LoadLevelAdditive(string sceneName)
{
SceneManager.LoadScene(sceneName, LoadSceneMode.Additive);
}
public async void LoadLevelAsync(string sceneName)
{
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
while (!op.isDone)
{
await Awaitable.NextFrameAsync();
}
}
}
Active Scene and GameObject Creation
Multiple scenes can be loaded, but only one is the Active Scene. Any new GameObject instantiated via script is placed inside the active scene.
Scene levelScene = SceneManager.GetSceneByName("Level1");
SceneManager.SetActiveScene(levelScene);
Moving GameObjects Between Scenes
Use SceneManager.MoveGameObjectToScene() to transfer a root GameObject from its current scene to another loaded scene:
Scene targetScene = SceneManager.GetSceneByName("PersistentManagers");
SceneManager.MoveGameObjectToScene(gameObject, targetScene);
TL;DR
- Use
LoadSceneMode.Additiveto open multiple scenes at the same time. - Instantiated GameObjects go to the designated Active Scene.
- Move GameObjects between active scenes using
MoveGameObjectToScene().