Autogenerated ScriptableObject
s that are stable references to the scenes configured in Unity Build Settings.
- Scene references are automatically generated/refreshed whenever the scenes in Build Settings change or any scene is renamed/moved, no code or manual setup required
- Scene references are stable and based on their GUID: if a scene is renamed/moved, all existing references to the corresponding
SceneReference
are maintained - No extra files are created in your project: everything lives in the asset imported from an empty file that lives in the package's own folder
- Utility methods
SceneReference.Load
,SceneReference.LoadAsync
andSceneReference.UnloadAsync
to load/unload scenes directly from references
- Only Scenes enabled in Build Settings are generated
- Referencing scenes that are not in Build Settings is not supported at all
- If you have multiple build configurations that involve changing which Scenes are enabled, previous references to disabled ones will be missing from the build and will be
null
at runtime
Either:
- Use the openupm registry and install this package using the openupm-cli:
openupm add com.gilzoide.stable-scene-reference
- Install via Unity Package Manager using the following URL:
https://github.com/gilzoide/unity-scene-reference.git#1.0.0
- Clone this repository or download a snapshot of it directly inside your project's
Assets
orPackages
folder.
- Declare SceneReference fields in your scripts
- Use the Inspector to assign any of the
SceneReference
s automatically generated from your project's Build Settings - Use
SceneReference.Load
,SceneReference.LoadAsync
andSceneReference.UnloadAsync
to load/unload scenes. Alternatively, useSceneReference.BuildIndex
orSceneReference.Path
as argument to SceneManager load/unload methods. - Enjoy 🍾