Table of Contents

SceneManager

When does scene loading happen?

Scene loading and unloading happens at the start of the Update loop, within the EarlyUpdate.UpdatePreloading phase of the PlayerLoop, and once during the Initialization phase of the player, before the first Update loop.

Player Loop Phases:

The Scene Loading Queue

The scene loading queue is a pipeline, and only one AsyncOperation can progress at a time. Calling SceneManager.LoadSceneAsync or SceneManager.UnloadSceneAsync adds a new AsyncOperation onto the end of the queue.

During the UpdatePreloading phase, Unity will execute the next operation in the scene loading queue.

The scene loading pipeline only seems to execute a single operation, every other frame.[research needed] If you have 3 small scenes in the pipeline (Scene1, Scene2, Scene3), loading additively, the engine will load them at the following times:

Initialization

The Engine fully “flushes” the scene loading queue during initialization. This works differently than the way Unity loads scenes during the EarlyUpdate.

All AsyncOperations that are queued during initialization are fully loaded during initialization. For example, if SceneManager.LoadSceneAsync is called in the Awake of the very first scene1), the engine will load this new scene before finishing Initialization.

Scene unloads are probably flushed if they are in the pipeline, too.[research needed]

Build Pipeline

Scenes are built during standalone build in the following way:

  1. The active scenes are closed.
  2. Each Scene in the BuildSettings is opened. At this point prefabs are still prefab instances.
  3. EditorSceneManager.sceneOpened callback is called.
  4. Prefabs in the scene are flattened (turned into normal game objects).
  5. IProcessScene and PostProcessScene callbacks are called.
  6. The final scene file is saved into the standalone build file.
  7. Repeat for next scene.

Sample Scene Load (Editor)

Here is an example of a scene loading additively in the middle of a game, in the editor. Note that:

Scattered Notes


API Notes:

SceneManager.sceneLoaded

1)
ie. called before the first Update
2)
You might expect during the unload phase that isLoaded=true, but this is not the case, even though all of the Scene objects are still perfectly loaded and accessible
3)
Unlike MonoBehaviour events which are called at the end.