0
0
Unityframework~10 mins

Scene loading and unloading in Unity - Step-by-Step Execution

Choose your learning style9 modes available
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.
Execution Sample
Unity
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
    public void LoadAndUnload()
    {
        SceneManager.LoadScene("Level1", LoadSceneMode.Additive);
        SceneManager.UnloadSceneAsync("Level1");
    }
}
This code loads a scene named 'Level1' and then unloads it asynchronously.
Execution Table
StepActionScene StateResult
1Call LoadScene("Level1")Level1: Not LoadedStarts loading Level1 scene
2SceneManager loads Level1Level1: LoadingScene assets load into memory
3Level1 scene becomes activeLevel1: Loaded and ActiveScene is ready to use
4Call UnloadSceneAsync("Level1")Level1: Loaded and ActiveStarts unloading Level1 scene
5SceneManager unloads Level1Level1: UnloadingScene assets removed from memory
6Level1 scene fully unloadedLevel1: Not LoadedScene no longer in memory
💡 Scene is fully unloaded, no longer active or in memory
Variable Tracker
VariableStartAfter LoadSceneAfter Scene ActiveAfter UnloadSceneAsyncAfter Unload Complete
SceneStateNot LoadedLoadingLoaded and ActiveUnloadingNot Loaded
Key Moments - 3 Insights
Why does the scene state change from 'Loading' to 'Loaded and Active'?
Because after LoadScene is called, Unity loads all scene assets, then activates the scene making it ready to use (see execution_table steps 2 and 3).
What happens if you try to unload a scene that is not loaded?
Nothing happens because the scene is not in memory; unloading only works on loaded scenes (see execution_table step 4 where unload starts only if scene is loaded).
Is unloading a scene synchronous or asynchronous?
Unloading is asynchronous, meaning it happens in the background without freezing the game (see execution_table step 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the scene state immediately after calling LoadScene?
ALoading
BLoaded and Active
CNot Loaded
DUnloading
💡 Hint
Check execution_table row 1 and 2 for scene state changes after LoadScene call.
At which step does the scene become ready for use?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at execution_table step where scene state is 'Loaded and Active'.
If you skip calling UnloadSceneAsync, what happens to the scene state?
AScene goes to Unloading state
BScene becomes Not Loaded automatically
CScene stays Loaded and Active
DScene reloads again
💡 Hint
Refer to variable_tracker and execution_table steps 4-6 about unloading process.
Concept Snapshot
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.
Full Transcript
This visual execution shows how Unity loads and unloads scenes step-by-step. First, LoadScene is called, which starts loading the scene assets. Once loaded, the scene becomes active and ready to use. Later, UnloadSceneAsync is called to remove the scene from memory asynchronously. The scene state changes from Not Loaded to Loading, then Loaded and Active, then Unloading, and finally back to Not Loaded. This process helps manage game memory and scene transitions smoothly.