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>, ISerializationCallbackReceiverImplements: 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:
string → Scene
implicit operator Scene(string)
Calls SceneManager.GetScene(sceneNameOrPath) — looks up in the SceneGraph
UnityScene → Scene
implicit operator Scene(UnityScene)
Calls SceneManager.GetScene(unityScene)
Scene → UnityScene
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
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
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
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.
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
Implicit string conversion requires SceneGraph The implicit operator Scene(string) calls SceneManager.GetScene(), which searches the SceneGraph. If the SceneGraph is not initialized or the scene is not registered, this returns null. Always ensure scenes are added to the SceneGraph before using string conversion.
No default constructor Scene has no public parameterless constructor. At runtime, scenes are only created through deserialization or implicit operators. In the Editor, use new Scene(sceneAsset).
Editor-only SceneAsset The Asset property and the Scene(SceneAsset) constructor only exist in UNITY_EDITOR. Do not reference them in runtime code without #if UNITY_EDITOR guards.
Examples
String-to-Scene Conversion
Comparing Scenes
Unity Interop
See Also
SceneManager — static API that resolves scene lookups
SceneGraph — the graph containing all registered scenes
SceneNode — graph node wrapping a
SceneSceneManagement Overview — system overview
Last updated