Class SceneManager
- Namespace
- KeenEyes
- Assembly
- KeenEyes.Core.dll
Manages scene spawning, unloading, and entity scene membership.
public sealed class SceneManager
- Inheritance
-
SceneManager
- Inherited Members
Remarks
This is an internal manager class that handles scene lifecycle operations. The public API is exposed through Scenes.
Scenes are entity hierarchies with a root entity marked by SceneRootTag. Entities can belong to multiple scenes through reference counting via ReferenceCount.
This class is thread-safe: all operations can be called concurrently from multiple threads.
Properties
LoadedCount
Gets the number of currently loaded scenes.
public int LoadedCount { get; }
Property Value
Methods
AddToScene(Entity, Entity)
Adds an entity to a scene with an initial reference count of 1.
public void AddToScene(Entity entity, Entity scene)
Parameters
Remarks
Use this to associate an entity with a scene for the first time. For entities that need to be in multiple scenes, use TransitionEntity(Entity, Entity) after the initial add.
Exceptions
- InvalidOperationException
Thrown when either entity is not alive, when
sceneis not a valid scene root, or when the entity already has scene membership.
GetLoaded()
Gets all currently loaded scene root entities.
public IEnumerable<Entity> GetLoaded()
Returns
- IEnumerable<Entity>
An enumerable of all loaded scene root entities.
Remarks
Returns a snapshot to allow safe iteration while scenes may be loaded/unloaded.
GetScene(string)
Gets a loaded scene by name.
public Entity GetScene(string name)
Parameters
namestringThe name of the scene to find.
Returns
Remarks
If multiple instances of a scene with the same name are loaded, returns the most recently spawned instance.
IsLoaded(string)
Checks if a scene with the given name is currently loaded.
public bool IsLoaded(string name)
Parameters
namestringThe name of the scene to check.
Returns
- bool
trueif the scene is loaded; otherwise,false.
MarkPersistent(Entity)
Marks an entity as persistent across scene unloads.
public void MarkPersistent(Entity entity)
Parameters
entityEntityThe entity to mark as persistent.
Remarks
Entities with PersistentTag are never despawned by Unload(Entity) operations, regardless of their ReferenceCount.
Exceptions
- InvalidOperationException
Thrown when the entity is not alive.
RemoveFromScene(Entity, Entity)
Removes an entity from a scene by decrementing its reference count.
public bool RemoveFromScene(Entity entity, Entity scene)
Parameters
entityEntityThe entity to remove from the scene.
sceneEntityThe scene to remove the entity from.
Returns
- bool
trueif the entity was removed;falseif the entity is not alive, has no scene membership, or is not in the specified scene.
Remarks
If the reference count reaches zero and the entity does not have PersistentTag, the entity and its descendants are despawned.
Spawn(string)
Spawns a new scene instance with the given name.
public Entity Spawn(string name)
Parameters
namestringThe name of the scene to spawn.
Returns
- Entity
The root entity of the spawned scene.
Remarks
Creates a new scene root entity with SceneRootTag and SceneMetadata. Multiple instances of the same scene name can be spawned; each gets a unique SceneId.
The most recently spawned instance with a given name is returned by GetScene(string).
Exceptions
- ArgumentNullException
Thrown when
nameis null.
TransitionEntity(Entity, Entity)
Transitions an entity to another scene, incrementing its reference count.
public void TransitionEntity(Entity entity, Entity toScene)
Parameters
Remarks
If the entity already has SceneMembership, its ReferenceCount is incremented.
If the entity does not have SceneMembership, it is added with the target scene as origin and reference count of 1.
Use this when an entity needs to exist in multiple scenes simultaneously (e.g., an NPC following the player between areas).
Exceptions
- InvalidOperationException
Thrown when either entity is not alive or when
toSceneis not a valid scene root.
Unload(Entity)
Unloads a scene and despawns its entities.
public bool Unload(Entity sceneRoot)
Parameters
sceneRootEntityThe root entity of the scene to unload.
Returns
- bool
trueif the scene was unloaded;falseif it was not a valid scene root.
Remarks
For each entity with SceneMembership referencing this scene:
- If the entity has PersistentTag, it is skipped (never despawned).
- Otherwise, ReferenceCount is decremented.
- If the reference count reaches zero, the entity and its descendants are despawned.
The scene root entity itself is always despawned.