/UnitySceneReference

Simple way to reference a scene in Unity without typing manually the scene path.

Primary LanguageC#MIT LicenseMIT

Unity SceneReference

Keeps reference to a scene asset and tracks it's path in the editor, so it can be used in the game runtime.

Why

It's a well known fact that scenes can't be referenced like prefabs, textures etc. The Unity SceneManager API works with relative scene paths or names.

Use this class to avoid manually typing and updating scene path strings - it will try to do it for you as best as it can, including when building the player.

Installation

npm install -g openupm-cli
openupm add devlocker.utils.scenereference

openupm

  • Github upm package - merge this to your Packages/manifest.json
{
  "dependencies": {
    "devlocker.utils.scenereference": "https://github.com/NibbleByte/UnitySceneReference.git#upm"
}

Features

  • The SceneReference class works on lists, scriptable objects, game objects, multiple-select.
  • Small button on the right to add or remove from the build settings. The +/- sign and color indicate what the operation would be.
  • Paths are updated during build (guaranteed by the ISerializationCallbackReceiver).

Here is how it looks like:
SceneReference

Here is how it looks in debug mode (what data is stored):
SceneReferenceDebug

Here is how it looks in the code:
SceneReferenceCode

Credits & Similar Projects

Using the ISerializationCallbackReceiver was inspired by the JohannesMP's SceneReference implementation.

Another solution that builds a runtime look-up table instead of storing paths in the data members is Eflatun.SceneReference.