SceneManager
Static facade wrapping Unity's SceneManager with dependency-aware scene loading. Resolves dependency chains from the SceneGraph and loads prerequisite scenes automatically before the target scene. Supports both synchronous and async loading, and fires events for scene load/unload.
Definition
Namespace: Paragon.Core.SceneManagement Assembly: Paragon.dll
public class SceneManagerRemarks
SceneManager is the primary API for scene operations in the Paragon framework. It wraps Unity's UnityEngine.SceneManagement.SceneManager and adds dependency chain resolution via the SceneGraph.
Initialization
The class auto-initializes via [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]. In non-editor builds, it discovers the SceneGraph via Resources.FindObjectsOfTypeAll<SceneGraph>(). It also subscribes to Unity's sceneLoaded and sceneUnloaded callbacks to translate them into Paragon Scene-typed events.
Dependency Chain Loading
When loadDependencies is true (the default), LoadScene and LoadSceneAsync call GetDependencyChain() to perform an iterative depth-first search (DFS) that produces a topologically ordered list of dependencies. Dependencies are loaded before the target scene.
The DFS algorithm:
Pushes the target scene's node onto a stack
For each node, pushes unvisited dependencies (in reverse order) onto the stack
When a node has no more unvisited dependencies, it is popped and added to the result set
This produces a post-order traversal — dependencies appear before dependents
Load Scene Mode
After loading the first dependency (or the target scene if there are no dependencies), the mode is forced to ADDITIVE for all subsequent loads in the chain. When the original mode is SINGLE, the target scene is set as the active scene once loading completes.
Quick Lookup
Load scene (sync)
SceneManager.LoadScene(scene)
Load scene (async)
await SceneManager.LoadSceneAsync(scene)
Unload scene (sync)
SceneManager.UnloadScene(scene)
Unload scene (async)
await SceneManager.UnloadSceneAsync(scene)
Load with dependencies
SceneManager.LoadScene(scene, loadDependencies: true) (default)
Load without dependencies
SceneManager.LoadScene(scene, loadDependencies: false)
Load additively
SceneManager.LoadScene(scene, loadSceneMode: LoadSceneMode.ADDITIVE)
Get active scene
SceneManager.GetActiveScene()
Set active scene
SceneManager.SetActiveScene(scene)
Check if loaded
SceneManager.IsSceneLoaded(scene)
Get all loaded scenes
SceneManager.GetLoadedScenes()
Look up scene by name
SceneManager.GetScene("MyScene")
Look up scene by path
SceneManager.GetScene("Assets/Scenes/MyScene.unity")
Move object to scene
SceneManager.MoveGameObjectToScene(go, scene)
Move object to active scene
SceneManager.MoveGameObjectToActiveScene(go)
Listen for loads
SceneManager.SceneLoaded += handler
Listen for unloads
SceneManager.SceneUnloaded += handler
Fields
sceneGraph
SceneGraph
protected static
The scene graph used for lookups and dependency resolution
Events
SceneLoaded
Action<Scene>
Fired after a scene finishes loading (maps from Unity's sceneLoaded callback)
SceneUnloaded
Action<Scene>
Fired after a scene is unloaded (maps from Unity's sceneUnloaded callback)
Methods
LoadScene
Loads a scene synchronously with optional dependency chain resolution.
scene
Scene
—
The target scene to load
loadDependencies
bool
true
Whether to load dependency scenes first
loadSceneMode
LoadSceneMode
SINGLE
SINGLE unloads current scenes; ADDITIVE keeps them
Behavior:
If
loadDependenciesistrue, resolves the dependency chain (excluding the target) and loads each in orderAfter loading dependencies, forces mode to
ADDITIVEfor subsequent loadsLoads the target scene
If original mode was
SINGLE, subscribes toSceneLoadedto callSetActiveScenewhen the target finishes loading
LoadSceneAsync
Loads a scene asynchronously with optional dependency chain resolution. Returns a Task that completes when all scenes (dependencies + target) finish loading.
scene
Scene
—
The target scene to load
loadDependencies
bool
true
Whether to load dependency scenes first
loadSceneMode
LoadSceneMode
SINGLE
SINGLE unloads current scenes; ADDITIVE keeps them
Behavior:
Starts all dependency load operations and collects
AsyncOperationhandlesStarts the target scene load operation
Awaits all operations via
Yield.WaitUntil(() => all.isDone)If original mode was
SINGLE, sets the target as the active scene
UnloadScene
Unloads a scene. Wraps UnloadSceneAsync with async void.
scene
Scene
—
The scene to unload
unloadDependencies
bool
false
Whether to also unload dependency scenes
UnloadSceneAsync
Unloads a scene asynchronously. Returns a Task that completes when all unload operations finish.
scene
Scene
—
The scene to unload
unloadDependencies
bool
false
Whether to also unload dependency scenes
GetDependencyChain
Performs an iterative DFS to compute the full dependency chain for a scene, in topological order (dependencies first).
scene
Scene
The root scene to resolve dependencies for
Returns: An IEnumerable<Scene> containing all dependencies plus the target scene, in load order. The target scene appears last.
MoveGameObjectToScene
Moves a GameObject to the specified scene.
MoveGameObjectToActiveScene
Moves a GameObject to the currently active scene.
GetActiveScene
Returns the currently active Scene.
SetActiveScene
Sets a loaded scene as the active scene.
GetLoadedScenes
Returns all scenes from the SceneGraph that are currently loaded.
IsSceneLoaded
Checks if a scene is currently loaded and valid.
GetScene(string)
Looks up a scene by name or path. If the string contains '/', it matches by path; otherwise by name.
Returns: The matching Scene, or null if not found.
GetScene(UnityScene)
Looks up a Paragon Scene from a Unity scene, using the Unity scene's path.
TryGetScene
Attempts to look up a scene by name or path.
Returns: true if the scene was found in the SceneGraph.
GetUnityScene
Converts a Paragon Scene to a Unity Scene by looking up the path.
Extension Points
Subclassing SceneManager
The sceneGraph field is protected static, allowing subclasses to provide custom graph initialization:
The GetDependencyChain method is protected static, making it available to subclasses for custom loading logic.
Enums
LoadSceneMode
Common Pitfalls
All scenes must be in the SceneGraph The OnSceneLoaded and OnSceneUnloaded callbacks throw NotSupportedException if the loaded/unloaded scene is not found in the SceneGraph. The only exception is Unity's built-in splash screen (buildIndex == -1), which is silently skipped during unload.
UnloadScene is async void UnloadScene uses async void, which means exceptions are unobservable. For error handling, prefer UnloadSceneAsync which returns a Task.
LoadScene forces ADDITIVE after first dependency When loading with dependencies and LoadSceneMode.SINGLE, the first dependency uses SINGLE mode (unloading current scenes), but all subsequent loads in the chain use ADDITIVE. This means the first dependency unloads everything, then the rest load additively on top. Be aware of this ordering when designing scene dependencies.
Dependency chain does not skip already-loaded scenes GetDependencyChain returns all dependencies regardless of whether they are already loaded. LoadScene does not check IsSceneLoaded before loading — it may reload already-loaded scenes depending on the mode.
Static state survives domain reload Events (SceneLoaded, SceneUnloaded) and the sceneGraph reference are static. In the editor with domain reload disabled, stale event subscriptions may persist. The [RuntimeInitializeOnLoadMethod(SubsystemRegistration)] attribute handles re-initialization, but events are not cleared automatically.
Examples
Load a Level with Dependencies
Async Scene Transition
Listening to Scene Events
Checking Scene Status
See Also
Scene — scene reference type used by all methods
SceneGraph — the graph backing all scene lookups
SceneNode — graph node with dependency data
SceneManagement Overview — system overview
Last updated