Scenes
Advanced scene management made easy

Introduction

1
public static class API.Scenes
Copied!
Did you know Unity can manage multiple scenes at once?
Want to learn more about multi-scene architectures? read this
Multi-Scene Architecture
Heathen KB
The Scenes interface makes working with multiple scenes simple and straitforward and provides useful tools and events making it trivial to set up loading notifications, page loaders and more.

What can it do?

  • Single line call to load and unload multiple scenes at once
  • Iterate over available scenes and loaded scenes
  • We handle the coroutines and activations for you
  • Start, Update and Completed events and componenets make it easy to connect to your UI and other game systems.

Events

Started

1
API.Scenes.EventStarted;
Copied!
Invoked when a process is started. The provided paramiters will indicate what scenes are changing and in what way and progress for load, unload and overall will be reported.

Updated

1
API.Scenes.EventUpdated;
Copied!
Invoked on each frame of progress during an operation and indicates what scenes are being effected and how as well as the progress for unload, load and total progress.

Completed

1
API.Scenes.EventCompleted;
Copied!
Invoked when a process completes and indicates what scenes where effected.

How To

Get the available scenes

This will return an array of the Scenes available to the system. Typically this is not needed however in mod supported games the collection of scenes that are available may change at runtime compared to development time.
1
var scenes = API.Scenes.AvailableScenes;
Copied!
This returns all scenes known by the system rather or not they are currently loaded. To fetch only the array of scenes that are currently loaded you can use
1
var loadedScenes = API.Scenes.LoadedScenes;
Copied!

Check if a scene is loaded

In multi-scene games various systems can effect what scenes are loaded and unloaded when. It then offten becomes useful to test if a given scene is currently loaded or not.
1
if(API.Scenes.IsSceneLoaded(scene));
Copied!
You can test by scene build index or the name of the scene.

Set Scene Active

Unity only ever has 1 scene active at a time, the active scene dicates which lighting environment is used. You can set a given scene active at any time via
1
API.Scenes.SetSceenActive(scene);
Copied!

Transition between scenes

Unique to Heathen's system is the ability to transition between batches of scenes all at once. That is you can instruct the system to unload multiple scenes at the same time it is loading mutliple scenes and indicate which loaded scene you wish to make active if any.
Transition operations take a callback paramiter which is invoked every update frame and indicate the progress of the operation.
1
API.Scenes.Transition(componenet, from, to, setActive, callback);
Copied!
The transition operation has mutliple overloads to offer you the most efficent and simplest 1 line call possible for you given use case. You will notice that all Transition operations include a MonoBehaviour paramiter, this is used to manage the internal UnityEngine.SceneManager and its coroutines. You can pass any MonoBehaviour into this call so long as its not being unloaded
😄

Additive Load / Unload

You can add and remove scenes from the set of loaded scenes at anytime using the Load and Unload operations. These have the same requirements as the Transition operation in that they do requrie you pass in a MonoBehaviour reference.
1
API.Scenes.Load(componenet, scene, callback);
Copied!
1
API.Scenes.Unload(componenet, scenes, callback);
Copied!
Last modified 6mo ago