Game Development
Async loading
Learn to show a screen while loading a scene with LoadSceneAsync.
Asynchronous Scene Loading (LoadSceneAsync)
When loading heavy scenes, the synchronous LoadScene method can freeze the game for several seconds. SceneManager.LoadSceneAsync() executes the loading process asynchronously in the background.
using UnityEngine.SceneManagement;
// Asynchronous background loading without freeze
AsyncOperation op = SceneManager.LoadSceneAsync("LargeLevel");
The application remains responsive, enabling animated loading screens while the scene streams in.
AsyncOperation and Progress Bar
LoadSceneAsync returns an AsyncOperation object. Reading its operation.progress value (0.0 to 1.0) inside a coroutine loop directly drives a UI progress bar fillAmount.
IEnumerator LoadWithProgress(string sceneName) {
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
while (!op.isDone) {
float progress = op.progress;
yield return null;
}
}
This provides real-time visual feedback to players regarding how much of the level has loaded.
Exercise Print async operation and progress info
Assign "LoadSceneAsync" to operation and "100%" to progress. Print Operation: LoadSceneAsync | Progress: 100% to the console.
Show example solution
using System;
class Program
{
static void Main()
{
string operation = "LoadSceneAsync";
string progress = "100%";
Console.WriteLine("Operation: " + operation + " | Progress: " + progress);
}
}
Test yourself
-
Which method is used to load heavy scenes asynchronously in the background without freezing the game?
- SceneManager.LoadSceneAsync()
- SceneManager.FastLoad()
- SceneManager.ThreadRun()
- SceneManager.LoadSceneBlocking()
Show answer
SceneManager.LoadSceneAsync() — LoadSceneAsync loads the scene asynchronously on background threads, keeping the primary viewport responsive.
-
Invoke asynchronous scene load
AsyncOperation operation = SceneManager.____("Level2");
Show answer
AsyncOperation operation = SceneManager.LoadSceneAsync("Level2");
-
Async loading concepts
- LoadSceneAsync
- Loads scene in background without freeze
- AsyncOperation
- Tracks status and progress of async op
- operation.progress
- Loading progress between 0.0 and 1.0
- Loading Screen
- Shows loading progress to the player
Next lesson: Summary - Scene management