Skip to content

EntityHandle

Defined in: EntityHandle.ts:27

A reference to one life of an entity, read through current.

A pooled entity is reused: the same object serves many lives, so a plain reference to a released member silently becomes a reference to whatever the pool handed out next. A handle expires with the life it was taken in.

class Turret extends Entity {
private target?: EntityHandle<Enemy>;
onSpotted(enemy: Enemy) { this.target = enemy.handle(); }
update() {
const enemy = this.target?.current; // undefined once that enemy is gone
if (enemy) this.aimAt(enemy);
}
}

Create one with entity.handle(). The type parameter is output-only, so an EntityHandle<Enemy> can be stored where an EntityHandle<Entity> is expected but not the other way round.

T extends Entity = Entity

readonly current: T | undefined

Defined in: EntityHandle.ts:35

The entity while the captured life lasts, undefined once it ends — destroyed, or released back to its pool.

“Same life”, not “currently active”: an entity turned off with setActive(false) still resolves.