# LoadableSceneId

> Stable serialized identifier for a Scene asset so it can be packed into content directory builds and loaded asynchronously at runtime.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Loading](/engine/6000.6/script-reference/unity/loading.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IEquatable\<LoadableSceneId>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct LoadableSceneId : IEquatable<LoadableSceneId>
```

## Remarks

This type can be used for a field on a ScriptableObject or MonoBehaviour to hold a "pointer" to a scene. When an object with a LoadableSceneId field is included in a ContentDirectory build, the referenced scene is also automatically included in the build.

When authoring content in the Editor, use [LoadableSceneIdEditorUtility](/engine/6000.6/script-reference/unityeditor/loadablesceneideditorutility.md) to create LoadableSceneId objects and assign them to fields on ScriptableObject-derived classes.

A LoadableSceneId is only supported in content built with [BuildPipeline.BuildContentDirectory](/engine/6000.6/script-reference/unityeditor/buildpipeline/buildcontentdirectory.md). If a LoadableSceneId is found in serialized data during a Player or AssetBundle build, the reference is set to null in the build output and an error is logged. Suppress this error with [BuildOptions.SuppressLoadableErrors](/engine/6000.6/script-reference/unityeditor/buildoptions/suppressloadableerrors.md) for Player builds or [BuildAssetBundleOptions.SuppressLoadableErrors](/engine/6000.6/script-reference/unityeditor/buildassetbundleoptions/suppressloadableerrors.md) for AssetBundle builds.

When a scripting object that has LoadableSceneId fields loads, it does not automatically load the referenced scenes. Instead, scripts can use [SceneManager.LoadSceneAsync](/engine/6000.6/script-reference/unityengine/scenemanagement/scenemanager/loadsceneasync.md) to load the referenced scene when needed. Similarly, scripts can use [SceneManager](/engine/6000.6/script-reference/unityengine/scenemanagement/scenemanager.md) APIs to unload scenes when no longer needed.

In the Player, [SceneManager.LoadSceneAsync](/engine/6000.6/script-reference/unityengine/scenemanagement/scenemanager/loadsceneasync.md) loads the scene from built content. In Play mode it loads either the built scene or the live project scene, depending on where the LoadableSceneId came from. A LoadableSceneId reached from built content, for example through a root asset, loads the built scene, while one created with [LoadableSceneIdEditorUtility](/engine/6000.6/script-reference/unityeditor/loadablesceneideditorutility.md) loads the live project scene.

## Examples

```csharp
using System.Threading.Tasks;
using Unity.Loading;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace BuildDocExamples
{
    public class LoadableSceneId_Example : MonoBehaviour
    {
        // Example ScriptableObject with a LoadableSceneId field
        public class LevelData : ScriptableObject
        {
            public LoadableSceneId sceneReference;
        }

        async Task LoadLevel(LevelData levelData)
        {
            // Assuming nextLevel is a LoadableSceneId serialized on your ScriptableObject or MonoBehaviour:
            if (levelData.sceneReference.IsValid)
            {
                var loadOp = SceneManager.LoadSceneAsync(levelData.sceneReference, new LoadSceneParameters(LoadSceneMode.Single));
                while (!loadOp.isDone)
                    await Awaitable.NextFrameAsync();
            }
        }
    }
}
```

## Properties

| Property                                                                            | Description                                                  |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| [IsValid](/engine/6000.6/script-reference/unity/loading/loadablesceneid/isvalid.md) | True if this LoadableSceneId is initialized with valid data. |
