Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

SceneManager.GetSceneByLoadableSceneId

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static Scene GetSceneByLoadableSceneId(LoadableSceneId loadableSceneId);

Parameters

Parameter Description
loadableSceneId The identifier for the specific scene asset to retrieve.

Returns

Scene A valid Scene when a matching scene instance is currently loaded; otherwise an invalid Scene.

Description

The Scene handle for a scene that is already loaded and originated from the given LoadableSceneId.

This is only meaningful after SceneManager.LoadSceneAsync (or an equivalent load path) has completed while the owning content directory was registered with ContentLoadManager.RegisterContentDirectory.

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); } }