SceneManager.Load
- Game Development course
- Intermediate
- Lesson 56/83
- 4 min
Learn to load a scene with SceneManager.LoadScene.
SceneManager and LoadScene
To switch scenes programmatically in Unity, the UnityEngine.SceneManagement namespace is imported. Calling SceneManager.LoadScene() with a scene name or build index transitions to the new scene.
using UnityEngine.SceneManagement;
// Loading a new scene by its asset name
SceneManager.LoadScene("Level1");Executing this method reads the target scene asset from storage and activates it.
Scene Transition and Single Mode
By default, LoadScene operates in LoadSceneMode.Single mode. This mode wipes all GameObjects belonging to the current scene from memory before loading the new scene cleanly.
// Single scene transition by index (Single is default)
SceneManager.LoadScene(1, LoadSceneMode.Single);This guarantees that residual enemies, projectiles, or obstacles from the prior level are completely purged.
Practice Print target scene and mode info
Assign "Level1" to targetScene and "Single" to mode. Print Loading: Level1 | Mode: Single to the console.
Starter code
using System;
class Program
{
static void Main()
{
// targetScene ve mode değerlerini tanımlayıp yazdır
}
}Sample solution
using System;
class Program
{
static void Main()
{
string targetScene = "Level1";
string mode = "Single";
Console.WriteLine("Loading: " + targetScene + " | Mode: " + mode);
}
}Expected output
Loading: Level1 | Mode: Single
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which namespace must be imported at the top of a C# script to utilize scene loading functions?
- System.IO.Compression
- UnityEngine.SceneManagement Correct answer
- UnityEngine.Audio
- UnityEngine.Physics2D
Explanation: The SceneManager class and related scene utilities reside within the UnityEngine.SceneManagement namespace.
2 Load scene by name
SceneManager.____("GamePlay");
SceneManager.LoadScene("GamePlay");
Explanation: To load a scene, the LoadScene method of the SceneManager class is called.
3 SceneManager concepts
| Term | Meaning |
|---|---|
SceneManager |
Static class for scene load & transition |
LoadScene |
Core method loading the specified scene |
LoadSceneMode.Single |
Closes old scene, opens only new one |
GetActiveScene() |
Method returning the active scene object |