RodGers
RodGers

Reputation: 185

What is happening in SceneManager.LoadSceneAsync()

There are two phases in SceneManager.LoadSceneAsync().

Firstly there's the preload phase. Second the activation phase.

What is exactly loading in each phase?

Upvotes: 2

Views: 4753

Answers (1)

Programmer
Programmer

Reputation: 125435

Pre-loading Scene:

A scene is loaded in the background. During this time, the resources such as textures, audios and 3D models referenced in that scene are loaded.

Activating Scene:

When the loaded scene is activated, the current scene is unloaded and the loaded scene will be active. When it becomes active, it will start executing the scripts referenced in that scene.

SceneManager.LoadSceneAsync will load the scene in the background. When the scene is loaded, it will be automatically activated. When activation is done, Unity will enable that loaded scene and the loaded scene will become the current scene.

Controlling Scene Activation:

Sometimes, you want to load the next scene when the current game is about to finish but you don't want it to activate it until the current game play is done. You are pre-loading the scene. This can be done by setting the AsyncOperation.allowSceneActivation property returned by the LoadSceneAsync function to false. By setting it to false, the scene will load but will not activate or run until you set it to true. Let's say you have finished playing the current scene, you can then activate the next scene which actually reduces the amount of time your player has to wait for the scene to finish loading. Loading and activating the next scene when the game is over will take more time than simply activating the scene.

Upvotes: 6

Related Questions