GetSceneByLoadableSceneId(LoadableSceneId)
The Scene handle for a scene that is already loaded and originated from the given LoadableSceneId.
Read time 1 minuteLast updated 13 days ago
Definition
- Type: Method
- Namespace: UnityEngine.SceneManagement
- Assembly: UnityEngine.CoreModule
public static Scene GetSceneByLoadableSceneId(LoadableSceneId loadableSceneId)
Parameters
The identifier for the specific scene asset to retrieve.
Returns
Type | Description |
|---|---|
| Scene | A valid Scene when a matching scene instance is currently loaded; otherwise an invalid Scene. |
Remarks
This is only meaningful after SceneManager.LoadSceneAsync (or an equivalent load path) has completed while the owning content directory was registered with ContentLoadManager.RegisterContentDirectory.
Examples
using System.Threading.Tasks;using Unity.Loading;using UnityEngine;using UnityEngine.SceneManagement;public class GetSceneByLoadableSceneIdExample{ // Example showing how to get the Scene handle after loading and activate it async Task Example(LoadableSceneId lobbySceneId) { AsyncOperation op = SceneManager.LoadSceneAsync(lobbySceneId, new LoadSceneParameters(LoadSceneMode.Additive)); while (!op.isDone) await Awaitable.NextFrameAsync(); Scene runtimeScene = SceneManager.GetSceneByLoadableSceneId(lobbySceneId); if (runtimeScene.IsValid()) SceneManager.SetActiveScene(runtimeScene); }}