Class: Entity
Stable handle for a single ECS entity. scene.GetEntity(id) always returns the same instance for a given id, so reference equality (===) is meaningful.
The handle owns no game state — all state lives in components keyed by id in the scene's ComponentRegistry. The methods below are convenience wrappers (name / parent / tag / activation / event emit) so game code doesn't repeatedly fetch HierarchyComponent, NameComponent, etc. for the common operations.
Implements
Constructors
Constructor
ts
new Entity(entityId, parentScene): Entity;Parameters
| Parameter | Type |
|---|---|
entityId | number |
parentScene | Scene |
Returns
Entity
Accessors
transform
Get Signature
ts
get transform(): TransformComponent;---------- Transform shortcuts ----------
Both return the live component, so writes to its fields still go through the auto-dirty setters: this.entity.transform.x += 5 * dt; // local; TransformSystem composes world this.entity.worldTransform.x = 100; // world override; TransformSystem reverse- composes local on the next tick Throws if the component is missing. Every Scene.CreateEntity has both.
Returns
worldTransform
Get Signature
ts
get worldTransform(): WorldTransformComponent;Returns
Methods
AddChild()
ts
AddChild(child): void;Parameters
| Parameter | Type |
|---|---|
child | Entity |
Returns
void
AddComponent()
ts
AddComponent<Component, Args>(type, ...args): Component;Type Parameters
| Type Parameter |
|---|
Component |
Args extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<Component, Args> |
...args | Args |
Returns
Component
Implementation of
AddScript()
ts
AddScript<T, Args>(type, ...args): T;Convenience for attaching a Script. Same as AddComponent but type-narrowed to Script subclasses. The script must have been registered with ComponentRegistry.RegisterScript.
Type Parameters
| Type Parameter |
|---|
T extends Script |
Args extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<T, Args> |
...args | Args |
Returns
T
AddTag()
ts
AddTag(tag): void;Add a tag (no-op if already present). Auto-adds TagComponent if absent.
Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
void
ClearListeners()
ts
ClearListeners(): void;Drop every listener. Called by Scene.DestroyEntity after firing the 'destroyed' event.
Returns
void
Destroy()
ts
Destroy(): void;Destroy this entity and every descendant. Equivalent to scene.DestroyEntity(this).
Returns
void
emit()
ts
emit<T>(name, payload?): void;Synchronously dispatch name with payload to all subscribed listeners.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
name | string |
payload? | T |
Returns
void
FindAncestor()
ts
FindAncestor(name): Entity | null;Walk up to a matching ancestor by name. Returns this entity if its own name matches.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Entity | null
FindChild()
ts
FindChild(nameOrPath): Entity | null;Find a descendant by NameComponent.name. Depth-first; supports forward-slash paths ('Background/Tower/Top'). Returns null if no match.
Parameters
| Parameter | Type |
|---|---|
nameOrPath | string |
Returns
Entity | null
GetChildAt()
ts
GetChildAt(index): Entity | null;Direct child at index, or null if out of range.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
Entity | null
GetChildCount()
ts
GetChildCount(): number;Number of direct children.
Returns
number
GetChildren()
ts
GetChildren(): Entity[];Snapshot of direct children. Mutating the returned array does NOT affect the hierarchy.
Returns
Entity[]
GetComponent()
ts
GetComponent<Component>(type): Component;Type Parameters
| Type Parameter |
|---|
Component |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<Component> |
Returns
Component
Implementation of
GetId()
ts
GetId(): number;Returns
number
Implementation of
GetName()
ts
GetName(): string;Read the entity's name from NameComponent. Returns '' if no NameComponent is attached.
Returns
string
GetParent()
ts
GetParent(): Entity | null;Returns the parent entity, or null if this is a scene root.
Returns
Entity | null
GetParentScene()
ts
GetParentScene(): Scene;Returns
Implementation of
GetTags()
ts
GetTags(): string[];Snapshot of all tags.
Returns
string[]
HasComponent()
ts
HasComponent<Component>(type): boolean;Type Parameters
| Type Parameter |
|---|
Component |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<Component> |
Returns
boolean
Implementation of
HasListeners()
ts
HasListeners(name): boolean;True if at least one listener is attached for the event name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
HasTag()
ts
HasTag(tag): boolean;Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
boolean
IsActive()
ts
IsActive(): boolean;Local active state — does this entity participate in updates/render IF its ancestors are also active? Mirrors Unity's GameObject.activeSelf.
Returns
boolean
IsActiveInHierarchy()
ts
IsActiveInHierarchy(): boolean;Effective active state in the scene graph — true iff this entity AND every ancestor are active. Updated on SetActive / reparent and by ActiveSystem; mirrors Unity's activeInHierarchy.
Returns
boolean
IsAncestorOf()
ts
IsAncestorOf(descendant): boolean;Is this entity an ancestor of descendant?
Parameters
| Parameter | Type |
|---|---|
descendant | Entity |
Returns
boolean
off()
ts
off<T>(
name,
cb?,
context?
): void;Remove listeners for an event name.
- off(name) removes every listener for
name - off(name, cb) removes every entry whose callback equals
cb - off(name, cb, ctx) removes only entries whose (cb, context) pair matches
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
name | string |
cb? | EntityEventHandler<T> |
context? | object |
Returns
void
on()
ts
on<T>(
name,
cb,
context?
): EntityEventUnsubscribe;Subscribe to an event. Returns an unsubscribe function for cleanup.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
name | string |
cb | EntityEventHandler<T> |
context? | object |
Returns
once()
ts
once<T>(
name,
cb,
context?
): EntityEventUnsubscribe;Subscribe to an event one time — the listener removes itself after the first fire.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters
| Parameter | Type |
|---|---|
name | string |
cb | EntityEventHandler<T> |
context? | object |
Returns
RemoveComponent()
ts
RemoveComponent<Component>(type): void;Type Parameters
| Type Parameter |
|---|
Component |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<Component> |
Returns
void
Implementation of
RemoveTag()
ts
RemoveTag(tag): void;Remove a tag (no-op if absent).
Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
void
SetActive()
ts
SetActive(active): void;Toggle local active state; the subtree's activeInHierarchy follows immediately.
Parameters
| Parameter | Type |
|---|---|
active | boolean |
Returns
void
SetName()
ts
SetName(name): void;Set the entity's name on NameComponent (adds the component if absent).
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
void
SetParent()
ts
SetParent(parent): void;Reparent this entity. Pass null to detach from any parent (make a scene root).
Parameters
| Parameter | Type |
|---|---|
parent | Entity | null |
Returns
void
TryGetComponent()
ts
TryGetComponent<Component>(type): Component | undefined;Type Parameters
| Type Parameter |
|---|
Component |
Parameters
| Parameter | Type |
|---|---|
type | ComponentClass<Component> |
Returns
Component | undefined