This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
scenemanager [2021/02/08 00:58] uninomiconadmin |
scenemanager [2022/01/30 19:55] (current) narry Added details about an undocumented quirk with occlusion culling in additive scenes |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SceneManager ====== | ||
+ | ==== When does scene loading happen? ==== | ||
+ | Scene loading and unloading happens at the start of the Update loop, within the '' | ||
+ | Player Loop Phases: | ||
+ | * __Initialization__ (Scene Loading happens here) | ||
+ | * Game Loop | ||
+ | * Early Update | ||
+ | * __UpdatePreloading__ (Scene Loading happens here) | ||
+ | * FixedUpdate | ||
+ | * Update | ||
- | # | ||
- | Notes: | + | ===== The Scene Loading Queue ===== |
- | `SceneManager.sceneLoaded` is called *after* the loaded Scene Awakes. | + | The scene loading queue is a pipeline, and only one AsyncOperation can progress at a time. Calling '' |
- | Scene Loading always happens at the start of the Update loop, within | + | |
- | The Unity scene flushing pipeline works differently in the initialization | + | During |
- | Scene loads thats are queued during initialization are blocked and fully loaded before the game starts. | + | |
- | For example, if SceneManager.LoadSceneAsync is called | + | |
- | It is untested if this is also the case for SceneManager.UnloadSceneAsync. However, because Unity documentation mentions that that the scene | + | The scene loading pipeline only seems to execute |
- | loading | + | |
- | during initialization. | + | |
- | Phases: | + | * Frame N+0: Scene1 |
- | - Initialization (Scene Loading happens here) | + | * Frame N+1: --- |
- | - Game Loop | + | * Frame N+2: Scene 2 |
- | - Early Update | + | * Frame N+3: --- |
- | - `UpdatePreloading` (Scene Loading happens here) | + | * Frame N+4: Scene 3 |
- | | + | |
- | (The scene load pipeline is fully flushed) I don't yet know how it handles unloads if they are in | ||
- | the pipeline then, so if we need this behaviour we should debug and see how it works. | ||
- | If scene unloads get flushed too, we'll need to add a bit of logic for it, in the same way LoadSceneAsync | ||
- | does. | ||
- | The scene loading pipeline only seems to load one scene, every other frame. That is to say if you have 3 small scenes in the pipeline (Scene1, Scene2, Scene3), loading additively, the engine will load them at the following times: | + | ==== Initialization ==== |
- | - Frame N+0: Scene1 | + | |
- | - Frame N+1: ---- | + | |
- | - Frame N+2: Scene 2 | + | |
- | - Frame N+3: ---- | + | |
- | - Frame N+4: Scene 3 | + | |
- | + | ||
- | ## Build Pipeline | + | |
- | Scenes are built during | + | The Engine fully " |
- | 0. The active | + | |
- | 1. Each Scene in the BuildSettings is opened. At this point prefabs are still prefab instances. | + | |
- | 2. EditorSceneManager.sceneOpened callback is called. | + | |
- | 3. Prefabs in the scene are flattened (turned into normal game objects). | + | |
- | 4. [IProcessScene] and PostProcessScene callbacks are called. | + | |
- | 5. The final scene file is saved into the standalone build file. | + | |
- | 6. Repeat for next scene | + | |
- | . | + | |
+ | **All** AsyncOperations that are queued during initialization are fully loaded during initialization. For example, if '' | ||
+ | Scene unloads are probably flushed if they are in the pipeline, too.< | ||
+ | |||
+ | ===== Build Pipeline ===== | ||
+ | |||
+ | Scenes are built during standalone build in the following way: | ||
+ | |||
+ | - The active scenes are closed. | ||
+ | - Each Scene in the BuildSettings is opened. At this point prefabs are still prefab instances. | ||
+ | - '' | ||
+ | - Prefabs in the scene are flattened (turned into normal game objects). | ||
+ | - [[IProcessScene]] and PostProcessScene callbacks are called. | ||
+ | - The final scene file is saved into the standalone build file. | ||
+ | - 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: | ||
+ | |||
+ | * Prefabs.MergePrefabs (turning prefabs into gameobjects) happens before any other callback. (editor only) | ||
+ | * Lightmapping is applied / loaded after Awake/ | ||
+ | * SceneManager.sceneLoaded happens after PostProcessScene. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===== Scattered Notes ===== | ||
+ | * During a scene load (ie. Awake) the loading scene has '' | ||
+ | * During a scene unload (ie. Destroy) the unloading scene has '' | ||
+ | * '' | ||
+ | * When using '' | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== API Notes: ===== | ||
+ | === SceneManager.sceneLoaded === | ||
+ | * Called **after** the loaded Scene Awakes. | ||
+ | |||
+ | |||
+ |