SceneGraph

ScriptableObject asset that holds the complete set of scene nodes for the project. Acts as the single source of truth for scene registration and dependency relationships. Implements IEnumerable<Scene> for LINQ-friendly iteration.

Definition

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

public class SceneGraph : ParagonScriptableObject, IEnumerable<Scene>

Inheritance: ScriptableObjectParagonScriptableObjectSceneGraph Implements: IEnumerable<Scene>

Remarks

SceneGraph is the central registry for the SceneManagement system. Every scene used by the game must be added to a SceneGraph asset. At runtime, the SceneManager loads the SceneGraph from Resources and uses it for all scene lookups, dependency chain resolution, and load/unload operations.

Internal Storage

Scenes are stored as a List<SceneNode> using [SerializeReference]. Each SceneNode wraps a Scene and maintains its own dependency list. When a scene is removed, the graph also removes it from all other nodes' dependency lists to maintain graph integrity.

Enumeration

SceneGraph implements IEnumerable<Scene>, allowing direct iteration over all registered scenes without exposing the internal SceneNode list:

foreach (Scene scene in sceneGraph)
{
    Debug.Log(scene.Name);
}

// LINQ works too
Scene found = sceneGraph.FirstOrDefault(s => s.Name == "MainMenu");

Quick Lookup

Goal
How

Add a scene

sceneGraph.AddScene(scene)

Remove a scene

sceneGraph.RemoveScene(scene)

Get a node

sceneGraph.GetSceneNode(scene)

Get all scenes

sceneGraph.GetAllScenes() or foreach

Get scene count

sceneGraph.Count

Check if contains scene

sceneGraph.Contains(scene) (via LINQ)

Clear all scenes

sceneGraph.Reset()

Properties

Property
Type
Access
Description

Count

int

public

Number of scene nodes in the graph

Fields

Field
Type
Access
Description

scenes

List<SceneNode>

private

Internal list of scene nodes ([SerializeReference])

Constructors

SceneGraph()

Private constructor. Initializes the scenes list. SceneGraph instances are created as ScriptableObject assets via Unity's asset creation workflow.

Methods

AddScene

Adds a new scene to the graph. Logs an error if the scene already exists.

Parameter
Type
Description

scene

Scene

The scene to register

Behavior:

  • If a SceneNode with the same Scene already exists, logs "Scene {name} already exists in the graph." and returns

  • Otherwise, creates a new SceneNode(this, scene) and appends it to the list

RemoveScene

Removes a scene and cleans up all dependency references to it across the graph.

Parameter
Type
Description

scene

Scene

The scene to remove

Behavior:

  1. Finds the SceneNode matching the scene

  2. If not found, returns silently

  3. Removes the node from the list

  4. Iterates all remaining nodes and calls RemoveDependency(node) on each to remove dangling references

GetSceneNode

Returns the SceneNode for a given scene, or null if not found.

Parameter
Type
Description

scene

Scene

The scene to look up

Returns: The matching SceneNode, or null.

GetAllScenes

Returns all scenes in the graph as a flat enumerable.

Returns: An IEnumerable<Scene> projected from the internal node list.

GetEnumerator

Implements IEnumerable<Scene>. Delegates to GetAllScenes().GetEnumerator().

Reset

Clears all scene nodes from the graph.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

Examples

Building a Scene Graph (Editor)

Querying the Graph

See Also

Last updated