8 KiB
uid |
---|
addressables-loading-scenes |
Loading Scenes
Use the Addressables.LoadSceneAsync method to load an Addressable Scene asset by address or other Addressable key object.
Note
Addressables.LoadSceneAsync uses the Unity Engine SceneManager.LoadSceneAsync method internally. API that affects the behaviour of SceneManager.LoadSceneAsync will most likely affect Addressables.LoadSceneAsync in the same way, for example Application.backgroundLoadingPriority.
The remaining parameters of the method correspond to those used with the SceneManager.LoadSceneAsync method:
- loadMode: whether to add the loaded Scene into the current Scene or to unload and replace the current Scene.
- loadSceneParameters: includes loadMode in addition to localPhysicsMode, used when loading the Scene to specify whether a 2D and/or 3D physics Scene should be created
- activateOnLoad: whether to activate the scene as soon as it finishes loading or to wait until you call the SceneInstance object's ActivateAsync method. Corresponds to the AsyncOperation.allowSceneActivation option. Defaults to true.
- priority: the priority of the AsyncOperation used to load the Scene. Corresponds to the AsyncOperation.priority option. Defaults to 100.
Warning
Setting the
activateOnLoad
parameter to false blocks the AsyncOperation queue, including the loading of any other Addressable assets, until you activate the scene. To activate the scene, call the ActivateAsync method of the SceneInstance returned by LoadSceneAsync. See AsyncOperation.allowSceneActivation for additional information.
The following example loads a scene additively. The Component that loads the Scene, stores the operation handle and uses it to unload and release the Scene when the parent GameObject is destroyed.
[!code-cssample]
See the Scene loading project in the Addressables-Sample repository for additional examples.
If you load a Scene with LoadSceneMode.Single, the Unity runtime unloads the current Scene and calls Resources.UnloadUnusedAssets. See Releasing Addressable assets for more information.
Note
In the Editor, you can always load scenes in the current project, even when they are packaged in a remote bundle that is not available and you set the Play Mode Script to Use Existing Build. The Editor loads the Scene using the asset database.