Loading and unloading scenes lets you change what the player sees and interacts with. It helps keep your game organized and saves memory by only using what is needed.
Scene loading and unloading in Unity
using UnityEngine.SceneManagement; // To load a scene by name SceneManager.LoadScene("SceneName"); // To load a scene additively (keep current scenes) SceneManager.LoadScene("SceneName", LoadSceneMode.Additive); // To unload a scene by name SceneManager.UnloadSceneAsync("SceneName");
Use LoadSceneMode.Additive to load a scene without removing the current one.
Unloading scenes frees memory but only works on scenes loaded additively.
SceneManager.LoadScene("MainMenu");SceneManager.LoadScene("Level2", LoadSceneMode.Additive);SceneManager.UnloadSceneAsync("Level1");This script listens for key presses. Pressing 'L' loads a scene called "GameScene" without removing the current scene. Pressing 'U' unloads "GameScene" to free memory.
using UnityEngine; using UnityEngine.SceneManagement; public class SceneSwitcher : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.L)) { // Load the "GameScene" additively SceneManager.LoadScene("GameScene", LoadSceneMode.Additive); Debug.Log("GameScene loaded additively."); } if (Input.GetKeyDown(KeyCode.U)) { // Unload the "GameScene" SceneManager.UnloadSceneAsync("GameScene"); Debug.Log("GameScene unloading started."); } } }
Always check that the scene name matches exactly what is in your build settings.
Loading scenes additively is useful for UI or multi-part worlds.
Unloading scenes is asynchronous, so it happens over time without freezing the game.
Use SceneManager.LoadScene to load scenes by name.
Use LoadSceneMode.Additive to keep current scenes when loading new ones.
Unload scenes with SceneManager.UnloadSceneAsync to save memory.
Practice
Solution
Step 1: Understand scene loading purpose
Loading a scene changes the visible content by switching or adding new scenes.Step 2: Compare other options
Deleting objects, saving progress, or pausing are unrelated to scene loading.Final Answer:
It changes what the player sees by switching or adding scenes. -> Option AQuick Check:
Scene loading = change visible scenes [OK]
- Confusing loading with saving game progress
- Thinking loading deletes objects
- Assuming loading pauses the game
Solution
Step 1: Recall Unity scene loading syntax
The correct method is LoadScene with scene name and LoadSceneMode.Additive as parameters.Step 2: Check each option
Only SceneManager.LoadScene("Level2", LoadSceneMode.Additive); uses the correct method and enum for additive loading.Final Answer:
SceneManager.LoadScene("Level2", LoadSceneMode.Additive); -> Option AQuick Check:
LoadScene + LoadSceneMode.Additive = correct syntax [OK]
- Using non-existent methods like LoadSceneAdditive
- Passing boolean instead of LoadSceneMode enum
- Confusing AddScene with LoadScene
SceneManager.LoadScene("Menu");
SceneManager.LoadScene("Game", LoadSceneMode.Additive);Solution
Step 1: Understand default and additive loading
The first call loads "Menu" scene normally (single mode), replacing current scenes. The second call loads "Game" additively, adding it without unloading "Menu".Step 2: Analyze the sequence
Since the second call uses additive mode, both scenes "Menu" and "Game" will be loaded together.Final Answer:
Both "Menu" and "Game" scenes will be loaded together. -> Option CQuick Check:
Additive loading adds scene without unloading [OK]
- Assuming first load is replaced by second always
- Thinking additive unloads previous scenes
- Believing multiple loads cause errors
SceneManager.UnloadScene("Level1");Solution
Step 1: Check Unity API for unloading scenes
SceneManager.UnloadScene requires a Scene object as parameter, not a string name. No overload accepts string directly.Step 2: Analyze the code
The code will not compile. Correct usage: Scene scene = SceneManager.GetSceneByName("Level1"); SceneManager.UnloadScene(scene);Final Answer:
UnloadScene requires a Scene object, not a string. -> Option DQuick Check:
UnloadScene(Scene), not (string) [OK]
- Passing string name instead of Scene object
- Thinking UnloadScene is deprecated
- Assuming the code runs without error
Solution
Step 1: Check if "Battle" scene is already loaded
Use SceneManager.GetSceneByName("Battle").isLoaded to verify if scene is loaded.Step 2: Load "Battle" additively if not loaded
If not loaded, call LoadScene with LoadSceneMode.Additive to keep "Town" scene loaded.Final Answer:
if (!SceneManager.GetSceneByName("Battle").isLoaded) { SceneManager.LoadScene("Battle", LoadSceneMode.Additive); } -> Option BQuick Check:
Check loaded + additive load = correct approach [OK]
- Loading scene in single mode, unloading current scene
- Not checking if scene is already loaded
- Unloading current scene before loading new one
Ready to prove it?
Pass the test and this pattern moves unknown
