Skip to content

Class: Scene ​

Constructors ​

Constructor ​

ts
new Scene(name?): Scene;

Parameters ​

ParameterTypeDefault value
namestring"Scene"

Returns ​

Scene

Methods ​

Clear() ​

ts
Clear(): void;

Returns ​

void


CreateCamera() ​

ts
CreateCamera(name, configure?): Entity;

Create a camera entity. Lives in world space (not under a Canvas). Pass configure to set camera fields inline; otherwise edit the returned CameraComponent directly.

Parameters ​

ParameterType
namestring
configure?(camera) => void

Returns ​

Entity


CreateCanvas() ​

ts
CreateCanvas(
   name, 
   referenceWidth?, 
   referenceHeight?, 
   scaleMode?
): Entity;

Create a 2D root entity. Carries CanvasComponent + UITransformComponent sized to the reference resolution. Anything subsequently parented under this canvas (or a descendant) is auto-detected as 2D and gets UI components attached.

Parameters ​

ParameterTypeDefault value
namestringundefined
referenceWidthnumber1080
referenceHeightnumber1920
scaleModeCanvasScaleModeCanvasScaleMode.Fit

Returns ​

Entity


CreateEntity() ​

ts
CreateEntity(name, parent?): Entity;

Create an entity. The foundational set is always attached: Name, Active, Hierarchy, Layer, Transform, WorldTransform. If parent (or any ancestor) carries a CanvasComponent, the new entity also gets UITransform + PivotOffset — 2D detection is by ancestry, not a flag the caller has to set. A child starts on its parent's layer (a Canvas starts on UI, so its content does too).

Parameters ​

ParameterTypeDefault value
namestringundefined
parentEntity | nullnull

Returns ​

Entity


Deserialize() ​

ts
Deserialize(json): void;

Parameters ​

ParameterType
jsonSerializedScene

Returns ​

void


DestroyEntity() ​

ts
DestroyEntity(entity): void;

Parameters ​

ParameterType
entityEntity

Returns ​

void


Find() ​

ts
Find(name): Entity | null;

---------- Scene-wide queries ---------- O(n) scans. Cache the result if you call them in hot paths.

Parameters ​

ParameterType
namestring

Returns ​

Entity | null


FindAll() ​

ts
FindAll(name): Entity[];

Parameters ​

ParameterType
namestring

Returns ​

Entity[]


FindAllByTag() ​

ts
FindAllByTag(tag): Entity[];

Parameters ​

ParameterType
tagstring

Returns ​

Entity[]


FindByTag() ​

ts
FindByTag(tag): Entity | null;

Parameters ​

ParameterType
tagstring

Returns ​

Entity | null


GetCameras() ​

ts
GetCameras(): Entity[];

Every camera in the scene, unsorted. CameraSystem re-sorts these by depth each tick.

Returns ​

Entity[]


GetChildOrderVersion() ​

ts
GetChildOrderVersion(): number;

Read by HierarchySystem to know a reorder happened. Not for general use.

Returns ​

number


GetComponentRegistry() ​

ts
GetComponentRegistry(): ComponentRegistry;

Returns ​

ComponentRegistry


GetEntitiesWithComponent() ​

ts
GetEntitiesWithComponent<T>(type): Entity[];

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
typeComponentClass<T>

Returns ​

Entity[]


GetEntitiesWithComponents() ​

ts
GetEntitiesWithComponents<T>(...types): Entity[];

Type Parameters ​

Type Parameter
T extends readonly ComponentClass<any, any[]>[]

Parameters ​

ParameterType
...typesT

Returns ​

Entity[]


GetEntity() ​

ts
GetEntity(entityId): Entity;

Parameters ​

ParameterType
entityIdnumber

Returns ​

Entity


GetHierarchyVersion() ​

ts
GetHierarchyVersion(): number;

Read by ActiveSystem to know a reparent happened. Not for general use.

Returns ​

number


GetLoadedSceneOf() ​

ts
GetLoadedSceneOf(entity): LoadedScene | null;

The additively loaded scene entity came from (through its root), or null for this scene's own.

Parameters ​

ParameterType
entityEntity

Returns ​

LoadedScene | null


GetLoadedScenes() ​

ts
GetLoadedScenes(): readonly LoadedScene[];

Returns ​

readonly LoadedScene[]


GetMainCamera() ​

ts
GetMainCamera(): Entity | null;

The "main" camera: lowest depth among enabled, in-hierarchy screen cameras. Returns null if the scene has none. Same convention as Unity's Camera.main.

Returns ​

Entity | null


GetName() ​

ts
GetName(): string;

Returns ​

string


GetRootEntities() ​

ts
GetRootEntities(): Entity[];

Returns ​

Entity[]


GetRootIds() ​

ts
GetRootIds(): readonly number[];

Root entity ids in draw order. Live — copy before mutating the hierarchy while iterating.

Returns ​

readonly number[]


HasEntity() ​

ts
HasEntity(entityId): boolean;

Parameters ​

ParameterType
entityIdnumber

Returns ​

boolean


Instantiate() ​

ts
Instantiate(
   data, 
   parent?, 
   keepExternalRefs?
): Entity[];

Adds serialized entities to this scene without clearing it and returns the payload's roots. Entries whose parent isn't in the payload attach under parent. Entity refs inside the payload are remapped; refs pointing outside it are kept only with keepExternalRefs (a same-scene duplicate) and nulled otherwise (a prefab's saved ids mean nothing here).

Parameters ​

ParameterTypeDefault value
dataSerializedSubtreeundefined
parentEntity | nullnull
keepExternalRefsbooleanfalse

Returns ​

Entity[]


InstantiatePrefab() ​

ts
InstantiatePrefab(assetId, parent?): Entity | null;

Spawns a prefab loaded as a 'json' asset (an *.prefab.json file). Returns its root, or null when the asset isn't loaded / isn't a prefab.

Parameters ​

ParameterTypeDefault value
assetIdstringundefined
parentEntity | nullnull

Returns ​

Entity | null


IsInstantiating() ​

ts
IsInstantiating(): boolean;

True while a scene load / additive load / prefab spawn is building entities: fields and hierarchy aren't final yet.

Returns ​

boolean


IsUnderCanvas() ​

ts
IsUnderCanvas(entity): boolean;

Parameters ​

ParameterType
entityEntity

Returns ​

boolean


LoadAdditive() ​

ts
LoadAdditive(json, key?): LoadedScene;

---------- Additive scenes ---------- One Scene runs at a time, so an additively loaded scene's entities join this one as extra roots (drawn after the existing ones) and are tracked as a group to unload together. Refs inside the loaded scene are remapped; Clear (a scene switch) drops every group.

Parameters ​

ParameterTypeDefault value
jsonSerializedSceneundefined
keystringjson.name

Returns ​

LoadedScene


OnActiveRefreshed() ​

ts
OnActiveRefreshed(listener): () => void;

Called with the root of a subtree whose activeInHierarchy was just re-derived (SetActive, reparenting, a scene load or prefab spawn) — ScriptSystem runs OnEnable / OnDisable there.

Parameters ​

ParameterType
listener(rootId) => void

Returns ​

() => void


RefreshActive() ​

ts
RefreshActive(entity): void;

Re-derives activeInHierarchy (and underCanvas) for entity's subtree now rather than at ActiveSystem's next walk — SetActive and reparenting call it, so a script's deactivation is seen by the systems that run after it in the same tick (Unity applies it immediately too).

Parameters ​

ParameterType
entityEntity

Returns ​

void


ReorderChildren() ​

ts
ReorderChildren(parent, ordered): void;

Draw order among siblings, which mmpx takes from children order alone.

Reparenting is not a substitute: SetParent appends, so a child moved back to the parent it already had lands last and draws on top of everything regardless of where it sits. Nor is mutating children directly enough — HierarchySystem re-walks only when it sees a parent change, so an in-place shuffle is silently ignored until something unrelated dirties it.

ordered must be a permutation of the parent's current children: this reorders, it never adds, removes or reparents. A mismatch is a programming error and throws rather than half-applying, since a partial write would leave the hierarchy inconsistent.

Parameters ​

ParameterType
parentEntity
orderedreadonly number[]

Returns ​

void


ReorderRoots() ​

ts
ReorderRoots(ordered): void;

ReorderChildren for the scene roots: ordered must be a permutation of GetRootIds().

Parameters ​

ParameterType
orderedreadonly number[]

Returns ​

void


Serialize() ​

ts
Serialize(): SerializedScene;

---------- Serialization ---------- Round-trips via component schemas. Hidden components (WorldTransform, PivotOffset, Hierarchy) are skipped — they're system-derived or structural. Entity ids are remapped on load, so the result is value-equivalent, not id-equivalent. Entities are written depth-first in children order, so list order alone carries sibling / draw order.

Returns ​

SerializedScene


SerializeSubtree() ​

ts
SerializeSubtree(root): SerializedSubtree;

One entity and its descendants, root first with parent: null — the prefab / duplicate payload. Feed it back through Instantiate.

Parameters ​

ParameterType
rootEntity

Returns ​

SerializedSubtree


SetParent() ​

ts
SetParent(child, parent): void;

Parameters ​

ParameterType
childEntity
parentEntity | null

Returns ​

void


UnloadAdditive() ​

ts
UnloadAdditive(loaded): boolean;

Destroys a loaded scene's entities. False when it was already unloaded.

Parameters ​

ParameterType
loadedLoadedScene

Returns ​

boolean

© 2026 PlayAdGentic