Scene
A Scene is the space that holds every GameObject, light, and camera — each .unity file is a Scene: a level, a menu, or a distinct game state you load.
Imagine...
A Scene is like a single episode of a show. Each episode has its own set, characters, and story. When you cut to the next episode (load a Scene), the old set vanishes. Characters that survive every episode use DontDestroyOnLoad() — like the protagonist who never disappears between levels.
The concept in detail
A typical game has many Scenes: MainMenu, Level_01, Level_02, GameOver, Loading… Splitting them keeps memory in check — you only load what you need.
To switch Scenes, use the SceneManager class. LoadScene() is synchronous
(blocking — the game freezes), while LoadSceneAsync() loads in the background so you
can show a Loading Screen.
Additive Loading: load several Scenes at once, stacked on top of each other. Common for world streaming or splitting UI Scene from gameplay Scene.
A GameObject that must survive Scene loads uses DontDestroyOnLoad(gameObject). Always
pair it with a Singleton so you do not spawn a duplicate when the Scene reloads.
Scene flow
MainMenu
index: 0
Loading
index: 1
Level_01
index: 2
GameOver
index: 3
Single Mode
Load new Scene → unload the old one
Additive Mode
Load extra Scene → keep the old one
Hands-on steps
Create a new Scene
Menu File → New Scene to create a Scene.
Add it to Build Settings
File → Build Settings → drag the .unity file into the list. The index is the number used by LoadScene(index).
Switch Scenes from a script
Add using UnityEngine.SceneManagement; then call SceneManager.LoadScene().
Loading Screen with Async
Use a Coroutine + LoadSceneAsync(), read AsyncOperation.progress (0.0 → 0.9) to update a progress bar.
Interactive simulator
Click Load Scene to simulate a transition with a Loading Screen. Watch GameManager survive every Scene.
🔒 GameManager
DontDestroyOnLoad
Code example
Basicusing UnityEngine;
using UnityEngine.SceneManagement;
public class SceneBasics : MonoBehaviour
{
void Awake()
{
// Keep this object across every Scene (Singleton GameManager)
DontDestroyOnLoad(gameObject);
}
public void LoadLevel1()
=> SceneManager.LoadScene("Level_01"); // by name
public void RestartCurrentScene()
{
int idx = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(idx); // by index
}
public void LoadNextScene()
{
int next = SceneManager.GetActiveScene().buildIndex + 1;
SceneManager.LoadScene(next);
}
}Code example
Advancedusing System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SceneLoader : MonoBehaviour
{
public static SceneLoader Instance { get; private set; }
[SerializeField] private Slider progressBar;
void Awake()
{
// Singleton: only one instance may exist
if (Instance != null) { Destroy(gameObject); return; }
Instance = this;
DontDestroyOnLoad(gameObject);
}
public void LoadScene(string sceneName)
=> StartCoroutine(LoadAsync(sceneName));
private IEnumerator LoadAsync(string sceneName)
{
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
op.allowSceneActivation = false;
while (op.progress < 0.9f)
{
float progress = Mathf.Clamp01(op.progress / 0.9f);
if (progressBar) progressBar.value = progress;
yield return null;
}
if (progressBar) progressBar.value = 1f;
yield return new WaitForSeconds(0.5f);
op.allowSceneActivation = true;
}
}📌 Quick recap
- ▸A Scene must be in Build Settings before LoadScene can find it
- ▸
DontDestroyOnLoadkeeps an object across transitions - ▸Use Async + a Coroutine to build a Loading Screen
- ▸
Additivemode for world streaming and splitting UI
⚠️ Common mistakes
❌ Forgetting to add the Scene to Build Settings
"Scene not found in Build Settings" error
✅ File → Build Settings → Add Open Scenes
❌ DontDestroyOnLoad without a Singleton guard
Reloading the Scene creates a second GameManager
✅ if (Instance != null) Destroy(this);