EditorSceneManager

Sealed editor-time extension of SceneManager that adds scene opening/closing, SceneGraph asset persistence, Build Settings synchronization, and play mode scene management.

Definition

Namespace: Paragon.Core.SceneManagement.Editor Assembly: Paragon.Editor.dll

public sealed class EditorSceneManager : SceneManager

Inheritance: SceneManagerEditorSceneManager

Remarks

EditorSceneManager bridges the runtime SceneManager with Unity's editor scene APIs. It is initialized via [InitializeOnLoadMethod] and provides:

  • Scene open/close with dependency chain support — OpenScene() and CloseScene() can traverse SceneNode dependencies

  • SceneGraph persistence — The graph is stored at ProjectSettings/SceneGraph.asset using InternalEditorUtility serialization (not a standard Unity asset)

  • Build Settings syncApplySceneGraphToBuildSettings() keeps EditorBuildSettings.scenes in sync with the graph

  • Play mode management — On entering play mode, the current active scene is saved to EditorPrefs and restored via RuntimeInitialize after the "Main" scene loads

The class fires SceneOpened and SceneClosed events (editor-only) that wrap Unity's internal scene lifecycle callbacks. Scenes not found in the SceneGraph trigger a warning but are still handled gracefully.

Quick Lookup

Goal
How

Open a scene in editor

EditorSceneManager.OpenScene(scene)

Open scene with dependencies

EditorSceneManager.OpenScene(scene, openDependencies: true)

Close a scene

EditorSceneManager.CloseScene(scene)

Check if scene is open

EditorSceneManager.IsSceneOpened(scene)

Get all opened scenes

EditorSceneManager.GetOpenedScenes()

Get all project scenes

EditorSceneManager.GetAllScenesInProject()

Get the SceneGraph

EditorSceneManager.GetSceneGraph()

Save graph to disk

EditorSceneManager.SaveSceneGraphAsset()

Sync Build Settings

EditorSceneManager.ApplySceneGraphToBuildSettings()

Events

SceneOpened

Fired when a scene is opened in the editor. The Scene parameter may be null if the opened scene is not in the SceneGraph.

SceneClosed

Fired when a scene is closed in the editor. The Scene parameter may be null if the closed scene is not in the SceneGraph.

Methods

OpenScene

Opens a scene in the editor, optionally loading its dependency chain first.

Parameter
Type
Default
Description

scene

Scene

Scene to open

openDependencies

bool

false

Load dependency chain scenes first

openSceneMode

OpenSceneMode

SINGLE

SINGLE replaces all; ADDITIVE adds alongside

circle-info

When openDependencies is true, dependency scenes are opened first in ADDITIVE mode regardless of the initial openSceneMode, then the target scene is opened with the specified mode.

CloseScene

Closes a scene in the editor, optionally closing its dependency chain.

Parameter
Type
Default
Description

scene

Scene

Scene to close

closeDependencies

bool

false

Also close dependency chain scenes

GetOpenedScenes

Returns all SceneGraph scenes currently open in the editor.

Returns: Scenes from the graph that are currently loaded and valid.

IsSceneOpened

Checks if a scene is currently loaded in the editor.

GetAllScenesInProject

Scans the Assets folder for all .scene files, regardless of whether they're in the SceneGraph.

GetSceneGraph

Gets the current SceneGraph, loading or creating it as needed.

Returns: The singleton SceneGraph instance. Creates a new one if none exists.

LoadSceneGraphAsset

Loads the SceneGraph from ProjectSettings/SceneGraph.asset.

SaveSceneGraphAsset

Saves the current SceneGraph to ProjectSettings/SceneGraph.asset.

ApplySceneGraphToBuildSettings

Syncs EditorBuildSettings.scenes to match the SceneGraph scene list.

SaveCurrentModifiedScenesIfUserWantsTo

Prompts the user to save modified scenes. Wraps Unity's built-in dialog.

Returns: true if the user saved or discarded changes; false if cancelled.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated