Skip to content

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 ​

ParameterType
entityIdnumber
parentSceneScene

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 ​

TransformComponent


worldTransform ​

Get Signature ​

ts
get worldTransform(): WorldTransformComponent;
Returns ​

WorldTransformComponent

Methods ​

AddChild() ​

ts
AddChild(child): void;

Parameters ​

ParameterType
childEntity

Returns ​

void


AddComponent() ​

ts
AddComponent<Component, Args>(type, ...args): Component;

Type Parameters ​

Type Parameter
Component
Args extends unknown[]

Parameters ​

ParameterType
typeComponentClass<Component, Args>
...argsArgs

Returns ​

Component

Implementation of ​

IEntity.AddComponent


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 ​

ParameterType
typeComponentClass<T, Args>
...argsArgs

Returns ​

T


AddTag() ​

ts
AddTag(tag): void;

Add a tag (no-op if already present). Auto-adds TagComponent if absent.

Parameters ​

ParameterType
tagstring

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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
namestring
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 ​

ParameterType
namestring

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 ​

ParameterType
nameOrPathstring

Returns ​

Entity | null


GetChildAt() ​

ts
GetChildAt(index): Entity | null;

Direct child at index, or null if out of range.

Parameters ​

ParameterType
indexnumber

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 ​

ParameterType
typeComponentClass<Component>

Returns ​

Component

Implementation of ​

IEntity.GetComponent


GetId() ​

ts
GetId(): number;

Returns ​

number

Implementation of ​

IEntity.GetId


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 ​

Scene

Implementation of ​

IEntity.GetParentScene


GetTags() ​

ts
GetTags(): string[];

Snapshot of all tags.

Returns ​

string[]


HasComponent() ​

ts
HasComponent<Component>(type): boolean;

Type Parameters ​

Type Parameter
Component

Parameters ​

ParameterType
typeComponentClass<Component>

Returns ​

boolean

Implementation of ​

IEntity.HasComponent


HasListeners() ​

ts
HasListeners(name): boolean;

True if at least one listener is attached for the event name.

Parameters ​

ParameterType
namestring

Returns ​

boolean


HasTag() ​

ts
HasTag(tag): boolean;

Parameters ​

ParameterType
tagstring

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 ​

ParameterType
descendantEntity

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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
namestring
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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
namestring
cbEntityEventHandler<T>
context?object

Returns ​

EntityEventUnsubscribe


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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
namestring
cbEntityEventHandler<T>
context?object

Returns ​

EntityEventUnsubscribe


RemoveComponent() ​

ts
RemoveComponent<Component>(type): void;

Type Parameters ​

Type Parameter
Component

Parameters ​

ParameterType
typeComponentClass<Component>

Returns ​

void

Implementation of ​

IEntity.RemoveComponent


RemoveTag() ​

ts
RemoveTag(tag): void;

Remove a tag (no-op if absent).

Parameters ​

ParameterType
tagstring

Returns ​

void


SetActive() ​

ts
SetActive(active): void;

Toggle local active state; the subtree's activeInHierarchy follows immediately.

Parameters ​

ParameterType
activeboolean

Returns ​

void


SetName() ​

ts
SetName(name): void;

Set the entity's name on NameComponent (adds the component if absent).

Parameters ​

ParameterType
namestring

Returns ​

void


SetParent() ​

ts
SetParent(parent): void;

Reparent this entity. Pass null to detach from any parent (make a scene root).

Parameters ​

ParameterType
parentEntity | null

Returns ​

void


TryGetComponent() ​

ts
TryGetComponent<Component>(type): Component | undefined;

Type Parameters ​

Type Parameter
Component

Parameters ​

ParameterType
typeComponentClass<Component>

Returns ​

Component | undefined

Implementation of ​

IEntity.TryGetComponent

© 2026 PlayAdGentic