Class: Scene
Constructors
Constructor
ts
new Scene(name?): Scene;Parameters
| Parameter | Type | Default value |
|---|---|---|
name | string | "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
| Parameter | Type |
|---|---|
name | string |
configure? | (camera) => void |
Returns
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
| Parameter | Type | Default value |
|---|---|---|
name | string | undefined |
referenceWidth | number | 1080 |
referenceHeight | number | 1920 |
scaleMode | CanvasScaleMode | CanvasScaleMode.Fit |
Returns
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
| Parameter | Type | Default value |
|---|---|---|
name | string | undefined |
parent | Entity | null | null |
Returns
Deserialize()
ts
Deserialize(json): void;Parameters
| Parameter | Type |
|---|---|
json | SerializedScene |
Returns
void
DestroyEntity()
ts
DestroyEntity(entity): void;Parameters
| Parameter | Type |
|---|---|
entity | Entity |
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
| Parameter | Type |
|---|---|
name | string |
Returns
Entity | null
FindAll()
ts
FindAll(name): Entity[];Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Entity[]
FindAllByTag()
ts
FindAllByTag(tag): Entity[];Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
Entity[]
FindByTag()
ts
FindByTag(tag): Entity | null;Parameters
| Parameter | Type |
|---|---|
tag | string |
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
GetEntitiesWithComponent()
ts
GetEntitiesWithComponent<T>(type): Entity[];Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<T> |
Returns
Entity[]
GetEntitiesWithComponents()
ts
GetEntitiesWithComponents<T>(...types): Entity[];Type Parameters
| Type Parameter |
|---|
T extends readonly ComponentClass<any, any[]>[] |
Parameters
| Parameter | Type |
|---|---|
...types | T |
Returns
Entity[]
GetEntity()
ts
GetEntity(entityId): Entity;Parameters
| Parameter | Type |
|---|---|
entityId | number |
Returns
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
| Parameter | Type |
|---|---|
entity | Entity |
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
| Parameter | Type |
|---|---|
entityId | number |
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
| Parameter | Type | Default value |
|---|---|---|
data | SerializedSubtree | undefined |
parent | Entity | null | null |
keepExternalRefs | boolean | false |
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
| Parameter | Type | Default value |
|---|---|---|
assetId | string | undefined |
parent | Entity | null | null |
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
| Parameter | Type |
|---|---|
entity | Entity |
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
| Parameter | Type | Default value |
|---|---|---|
json | SerializedScene | undefined |
key | string | json.name |
Returns
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
entity | Entity |
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
| Parameter | Type |
|---|---|
parent | Entity |
ordered | readonly number[] |
Returns
void
ReorderRoots()
ts
ReorderRoots(ordered): void;ReorderChildren for the scene roots: ordered must be a permutation of GetRootIds().
Parameters
| Parameter | Type |
|---|---|
ordered | readonly 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
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
| Parameter | Type |
|---|---|
root | Entity |
Returns
SetParent()
ts
SetParent(child, parent): void;Parameters
| Parameter | Type |
|---|---|
child | Entity |
parent | Entity | null |
Returns
void
UnloadAdditive()
ts
UnloadAdditive(loaded): boolean;Destroys a loaded scene's entities. False when it was already unloaded.
Parameters
| Parameter | Type |
|---|---|
loaded | LoadedScene |
Returns
boolean