Originally based on https://github.com/JohannesMP/unity-scene-reference
A wrapper that provides the means to safely serialize SceneAsset References. Adds aditional controls for the serialized SceneAsset. This helps to have all-in-one tool to manage basic settings of your scene.
Supports build-settings scenes and, when com.unity.addressables is installed, also persists addressable scene metadata.
The runtime API returns wrapper operations that work across both SceneManager and Addressables loading.
- Unity 2022.3 LTS or higher
Install by git URL
https://github.com/der-hugo/SceneReference?path=com.derhugo.unity.scenereference
To your according assembly references add derHugo.Unity.SceneReference and then use
using derHugo.Unity.SceneReference;Then you can simply use the type SceneReference for exposing a SceneAsset field to the Inspector.
[SerializeField] private SceneReference _example;var loadOperation = _scene.LoadAsync(LoadSceneMode.Additive, activateOnLoad: false);
while (!loadOperation.IsDone)
{
Debug.Log(loadOperation.Progress);
yield return null;
}
if (loadOperation.IsReadyForActivation)
{
yield return loadOperation.ActivateAsync();
}It is up to the user to ensure the scene exists in the build settings so it is loadable at runtime.
To help with this, a custom PropertyDrawer displays the scene build settings state.
For regular scenes the runtime key is the scene path. For Addressables scenes the runtime key is GUID-first, with the address kept as inspector-facing information.
Internally we serialize a UnityEngine.Object reference to the SceneAsset which only exists at editor time.
Any time the object is serialized, we store the path provided by this Asset (assuming it was valid).
This means that, come build time, the string path of the scene asset is always already stored, which if the scene was added to the build settings means it can be loaded.
There is an implicit conversion to string returning the path so a SceneReference
can directly passed as a parameter to SceneManager.LoadScene
- When reverting back to a prefab which has the asset stored as null, Unity will show the property as modified despite having just reverted. This only happens on the first time, and reverting again fix it. Under the hood the state is still always valid and serialized correctly regardless.
- Scene Reference Example - Showcases usage of
SceneReference


