Skip to content

marc-antoine-girard/Unity3D-RuntimeScene

Repository files navigation

GitHub package.json version
GitHub issues GitHub pull requests GitHub last commit GitHub license

Unity3D-RuntimeScene

A simple class that lets you reference scenes in the Editor.

Summary

  • Allows referencing scenes in Unity's Inspector
  • Avoids scene name conflicts when using RuntimeScene methods
  • The resulting RuntimeScene instances in build are super lightweight
  • In the editor, allows loading scene not in Build Settings
  • Add or remove scenes from Build Settings using the Context Menu

Installation

Using git

  • In Window -> Package Manager -> Add package from git URL...
  • Paste https://github.com/marc-antoine-girard/Unity3D-RuntimeScene.git

Using OpenUPM

The package is available on the openupm registry. You can install it via openupm-cli.

openupm add com.marc-antoine-girard.runtimescene

Usage

Note If you're using Assemblies, don't forget to reference ShackLab.RuntimeScene

Here's a simple example on how to use RuntimeScene:

public class LoadScene : MonoBehaviour
{
    public RuntimeScene scene;
    void LoadingMethods()
    {
        // Load scene synchronously 
        scene.LoadScene();
        // Load scene asynchronously 
        scene.LoadSceneAsync();
    }
}

RuntimeScene has many overloaded methods, most mirroring SceneManager.LoadScene and SceneManager.LoadSceneAsync.

image

You can also use SceneManager's methods to load scenes, but it is NOT RECOMMENDED.

The biggest advantages of using RuntimeScene's methods over SceneManager are:

  • In Build, RuntimeScene uses the build Index by default instead of the scene's name, which avoids unnexpected behaviour when Build Settings contains multiple scenes with the same name

  • In the Editor, Scenes will load even if not in the Build Settings.

    • The intent behind this decision is to allow faster testing in some situation.

    • Note that loading a scene that is not in the Build Settings will throw a warning in the Editor, letting you know this won't work in build.

    • If you want to opt-out of this feature, you can define "DISABLE_LOAD_EDITOR" Edit -> Project Settings -> Player -> Other Settings -> Scripting Define Symbols

      Warning | Scene {scene name} is not in the build settings. Consider adding it if you plan on using it in build

Editor Tools

You will also get a warning box under the RuntimeScene when referencing a Scene that is not in Build Settings image

You can quickly add or remove the Scene using the Context Menu (right-click):

imageimage

RuntimeScene Methods

public void LoadScene();
public void LoadScene(LoadSceneMode mode);
public void LoadScene(LoadSceneParameters parameters);

public AsyncOperation LoadSceneAsync(bool allowSceneActivation = true);
public AsyncOperation LoadSceneAsync(LoadSceneMode mode, bool allowSceneActivation = true);
public AsyncOperation LoadSceneAsync(LoadSceneParameters parameters, bool allowSceneActivation = true);

Addressables

When using scenes with Addressables, you can use AssetReferenceScene.

Note AssetReferenceScene is only available when Addressables is in the project.

public class LoadScene : MonoBehaviour
{
    public AssetReferenceScene scene;
    void Start()
    {
        scene.LoadSceneAsync();
    }
}

Contributions

Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.

ko-fi

About

A simple class that lets you reference scenes in the Editor.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Languages