Skip to content

Entity

Defined in: Entity.ts:33

An entity is a named container of components with O(1) lookups by type.

new Entity(name?, tags?): Entity

Defined in: Entity.ts:72

string

Iterable<string, any, any>

Entity

readonly id: number

Defined in: Entity.ts:36

Unique auto-incrementing ID.


readonly optional key?: string

Defined in: Entity.ts:47

Stable identity key, scene-scoped. Set at spawn-time when options.key is passed to scene.spawn / entity.spawnChild; undefined otherwise. Used with scene.findByKey and as a stable id in reactive stores (e.g. a createSet<string>() persisted under "world.opened").


readonly name: string

Defined in: Entity.ts:38

Display name for debugging.


readonly tags: Set<string>

Defined in: Entity.ts:40

Tags for group queries.


timeScale: number = 1

Defined in: Entity.ts:62

Per-entity time-scale multiplier. Mirrors Scene.timeScale but scoped to this single entity: the engine composes the delta time passed to this entity’s components (and its ProcessComponent, particle emitters) as dt * scene.timeScale * entity.timeScale. 1 = normal speed, 0.5 = half speed, 0 = frozen, 2 = double speed.

Physics is deliberately NOT affected: PhysicsSystem steps a single shared Rapier world per scene under scene.timeScale only, so a rigid-body entity’s simulation cannot be individually slowed or sped up via this field. Use a kinematic body or scale velocities manually if you need per-body time control.


static [TRAITS_KEY]: Set<symbol>

Defined in: Entity.ts:34

get children(): ReadonlyMap<string, Entity>

Defined in: Entity.ts:114

Named children as a read-only map. Empty map if no children.

ReadonlyMap<string, Entity>


get isDestroyed(): boolean

Defined in: Entity.ts:104

True if destroy() has been called.

boolean


get parent(): Entity | null

Defined in: Entity.ts:109

The parent entity, or null if this is a root entity.

Entity | null


get scene(): Scene

Defined in: Entity.ts:89

The scene this entity belongs to. Throws if the entity is not attached to a scene — which in practice only happens before scene.spawn / addChild wires it up, or after destroy() tears it down. Inside lifecycle methods (setup, component onAdd, update, etc.) this is always safe to access.

For the rare case where you genuinely need to inspect whether an entity has a scene (e.g. defensive code in systems iterating a query result), use tryScene instead.

Scene


get tryScene(): Scene | null

Defined in: Entity.ts:99

The scene this entity belongs to, or null if detached.

Scene | null

_performDestroy(): void

Defined in: Entity.ts:361

Internal

Internal: perform actual destruction — remove all components and clear state. Called by Scene during endOfFrame flush.

void


_setKey(key): void

Defined in: Entity.ts:445

Internal

Internal: assign the stable identity key. Called by Scene._registerKey during spawn. Throws if the entity already has a key — keys are immutable for an entity’s lifetime.

string

void


_setScene(scene, callbacks): void

Defined in: Entity.ts:431

Internal

Internal: set the scene and callbacks. Called by Scene.spawn().

Scene | null

EntityCallbacks | null

void


add<C>(component): C

Defined in: Entity.ts:257

Add a component instance. Returns the component for chaining.

C extends Component

C

C


addChild(name, child): void

Defined in: Entity.ts:119

Add a named child entity. Auto-adds to parent’s scene if not already in one.

string

Entity

void


optional afterRestore(data, resolve): void

Defined in: Entity.ts:397

Called after components are restored during save/load. Rebuild non-serializable state here.

unknown

SnapshotResolver

void


destroy(): void

Defined in: Entity.ts:342

Mark for deferred destruction. Actual cleanup happens at end of frame.

void


emit(token): void

Defined in: Entity.ts:319

Emit a typed event on this entity. Bubbles to the scene.

EventToken<void>

void

emit<T>(token, data): void

Defined in: Entity.ts:320

Emit a typed event on this entity. Bubbles to the scene.

T

EventToken<T>

T

void


get<C>(cls): C

Defined in: Entity.ts:272

Get a component by class. Throws if not found.

C extends Component

ComponentClass<C>

C


getAll(): Iterable<Component>

Defined in: Entity.ts:337

Get all components as an iterable.

Iterable<Component>


getChild(name): Entity

Defined in: Entity.ts:243

Get a child by name. Throws if not found.

string

Entity


has(cls): boolean

Defined in: Entity.ts:288

Check if entity has a component of the given class.

ComponentClass

boolean


hasTrait<T>(token): this is Entity & T

Defined in: Entity.ts:400

Check if this entity’s class implements a given trait. Acts as a type guard.

T

TraitToken<T>

this is Entity & T


on<T>(token, handler): () => void

Defined in: Entity.ts:304

Subscribe to a typed event on this entity. Returns an unsubscribe function.

T

EventToken<T>

(data) => void

() => void


remove(cls): void

Defined in: Entity.ts:293

Remove a component by class.

ComponentClass

void


removeChild(name): Entity

Defined in: Entity.ts:228

Remove a named child. Returns the detached entity.

string

Entity


requireKey(): string

Defined in: Entity.ts:417

Return the stable key, or throw if this entity was spawned without one. Use inside component setup() when the component depends on identity (e.g. reading from a createSet keyed by entity key).

string


optional serialize(): unknown

Defined in: Entity.ts:394

Return a JSON-serializable snapshot of this entity’s custom state. Used by the save system.

unknown


optional setup(params): void

Defined in: Entity.ts:391

Optional setup method. Called by scene.spawn(Class, params) after the entity is wired to its scene, so components can access services. Override in subclasses — do NOT use the constructor for component setup.

unknown

void


spawnChild(name, options?): Entity

Defined in: Entity.ts:161

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

string

SpawnOptions

Entity

spawnChild<E>(name, Class, options?): E

Defined in: Entity.ts:162

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

E extends Entity

string

() => E

SpawnOptions

E

spawnChild<E, P>(name, Class, params, options?): E

Defined in: Entity.ts:167

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

E extends Entity

P

string

() => E & object

P

SpawnOptions

E

spawnChild<P>(name, blueprint, params, options?): Entity

Defined in: Entity.ts:173

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

P

string

Blueprint<P>

P

SpawnOptions

Entity

spawnChild(name, blueprint, options?): Entity

Defined in: Entity.ts:180

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

string

Blueprint<void>

SpawnOptions

Entity


tryGet<C>(cls): C | undefined

Defined in: Entity.ts:283

Get a component by class, or undefined if not found.

C extends Component

ComponentClass<C>

C | undefined


tryGetChild(name): Entity | undefined

Defined in: Entity.ts:252

Get a child by name, or undefined if not found.

string

Entity | undefined