Concept Flow - Scene loading and unloading
Start
Call LoadScene
Scene Loads
Scene Active
Call UnloadScene
Scene Unloads
Back to Start or Next Scene
This flow shows how a scene is loaded, becomes active, and then unloaded in Unity.
using UnityEngine; using UnityEngine.SceneManagement; public class SceneLoader : MonoBehaviour { public void LoadAndUnload() { SceneManager.LoadScene("Level1", LoadSceneMode.Additive); SceneManager.UnloadSceneAsync("Level1"); } }
| Step | Action | Scene State | Result |
|---|---|---|---|
| 1 | Call LoadScene("Level1") | Level1: Not Loaded | Starts loading Level1 scene |
| 2 | SceneManager loads Level1 | Level1: Loading | Scene assets load into memory |
| 3 | Level1 scene becomes active | Level1: Loaded and Active | Scene is ready to use |
| 4 | Call UnloadSceneAsync("Level1") | Level1: Loaded and Active | Starts unloading Level1 scene |
| 5 | SceneManager unloads Level1 | Level1: Unloading | Scene assets removed from memory |
| 6 | Level1 scene fully unloaded | Level1: Not Loaded | Scene no longer in memory |
| Variable | Start | After LoadScene | After Scene Active | After UnloadSceneAsync | After Unload Complete |
|---|---|---|---|---|---|
| SceneState | Not Loaded | Loading | Loaded and Active | Unloading | Not Loaded |
Scene loading and unloading in Unity:
- Use SceneManager.LoadScene("SceneName") to load a scene.
- Scene loads assets then becomes active.
- Use SceneManager.UnloadSceneAsync("SceneName") to unload asynchronously.
- Scene state changes: Not Loaded -> Loading -> Loaded and Active -> Unloading -> Not Loaded.
- Unloading frees memory without freezing the game.