Skip to content

Autogenerated ScriptableObjects that are stable references to the scenes configured in Build Settings, even if they are moved/renamed

License

Notifications You must be signed in to change notification settings

gilzoide/unity-scene-reference

Repository files navigation

Stable Scene Reference

openupm

Autogenerated ScriptableObjects that are stable references to the scenes configured in Unity Build Settings.

Features

  • 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 and SceneReference.UnloadAsync to load/unload scenes directly from references

Caveats

  • 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

How to install

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 or Packages folder.

How to use

  1. Declare SceneReference fields in your scripts
  2. Use the Inspector to assign any of the SceneReferences automatically generated from your project's Build Settings
  3. Use SceneReference.Load, SceneReference.LoadAsync and SceneReference.UnloadAsync to load/unload scenes. Alternatively, use SceneReference.BuildIndex or SceneReference.Path as argument to SceneManager load/unload methods.
  4. Enjoy 🍾

Related projects

About

Autogenerated ScriptableObjects that are stable references to the scenes configured in Build Settings, even if they are moved/renamed

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages