Scene

Serializable scene reference that wraps Unity's scene data with a path, name, and GUID. Provides implicit conversions to and from string and UnityEngine.SceneManagement.Scene, enabling seamless interop between the Paragon scene system and Unity's native scene API.

Definition

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

[Serializable]
public class Scene : IEquatable<Scene>, ISerializationCallbackReceiver

Implements: IEquatable<Scene>, ISerializationCallbackReceiver

Remarks

Scene acts as the fundamental scene identifier throughout the Paragon SceneManagement system. Instead of passing raw strings or Unity SceneAsset references, all APIs accept and return Scene instances.

Editor/Runtime Synchronization

In the Unity Editor, Scene holds a direct SceneAsset reference. The ISerializationCallbackReceiver callbacks keep the serialized scenePath, sceneName, and guid fields synchronized with the asset. At runtime (builds), only the serialized string fields exist — the SceneAsset reference is stripped by #if UNITY_EDITOR guards.

Implicit Operators

Three implicit operators allow transparent conversion:

Conversion
Operator
How

stringScene

implicit operator Scene(string)

Calls SceneManager.GetScene(sceneNameOrPath) — looks up in the SceneGraph

UnitySceneScene

implicit operator Scene(UnityScene)

Calls SceneManager.GetScene(unityScene)

SceneUnityScene

implicit operator UnityScene(Scene)

Calls SceneManager.GetUnityScene(scene) — looks up by path

Equality

Two Scene instances are equal if their scenePath, sceneName, and guid all match. The == and != operators are overloaded and delegate to Equals. Null-safe: null == null returns true.

Quick Lookup

Goal
How

Create from SceneAsset (Editor)

new Scene(sceneAsset)

Get from string

Scene scene = "MyScene"; (implicit operator)

Get from UnityScene

Scene scene = unityScene; (implicit operator)

Convert to UnityScene

UnityScene us = scene; (implicit operator)

Compare scenes

scene1 == scene2 (path + name + GUID)

Get scene name

scene.Name

Get scene path

scene.Path

Get scene GUID

scene.GUID

Get SceneAsset (Editor only)

scene.Asset

Properties

Property
Type
Access
Description

Path

string

public

Full asset path (e.g., "Assets/Scenes/Level01.unity")

Name

string

public

Scene file name without extension (e.g., "Level01")

GUID

string

public

AssetDatabase GUID for the scene asset

Asset

SceneAsset

public

Editor only — Direct reference to the Unity SceneAsset

Fields

Field
Type
Access
Description

sceneAsset

SceneAsset

private

Editor only — Serialized scene asset reference

scenePath

string

private

Serialized full asset path

sceneName

string

private

Serialized scene name (no extension)

guid

string

private

Serialized asset GUID

Constructors

Scene(SceneAsset) — Editor Only

Creates a Scene from a Unity SceneAsset, extracting path, name, and GUID from the AssetDatabase.

Parameter
Type
Description

sceneAsset

SceneAsset

The Unity scene asset to reference

Methods

Equals(Scene)

Compares by scenePath, sceneName, and guid.

GetHashCode

Hash based on Path, Name, and GUID.

ToString

Returns the scene name.

Operators

Serialization Callbacks

OnBeforeSerialize

Editor only — Refreshes scenePath, sceneName, and guid from the SceneAsset reference via AssetDatabase.

OnAfterDeserialize

Editor only — Restores the SceneAsset reference from scenePath via EditorApplication.delayCall to ensure the AssetDatabase is ready.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

String-to-Scene Conversion

Comparing Scenes

Unity Interop

See Also

Last updated