SpawnCommand

View source

ExtendsCommand

Builds a deferred component insertion for an entity.

The command stores an EntityHandle and an ordered component payload. The constructor does not allocate or change an entity. SpawnCommand#insert appends one component, SpawnCommand#insertPrefab appends a batch, and SpawnCommand#execute passes the accumulated values to World#insert. The world applies the insertion only when the command is executed; a stale entity handle has no effect.

Examples

const command = new SpawnCommand(entity)
command.insert(new Position2D(10, 20))
command.insertPrefab([new Name('player')])
command.execute(world)

Constructor


constructor(entity: EntityHandle)

View source

Parameters

NameDescriptionDefault
entity

Entity that will receive the components.

—

Properties


Methods


insert<T>(component: T): void

View source

Appends one component to this command’s payload.

The component is accumulated until SpawnCommand#execute is called; this method does not insert into the world immediately.

Type Parameters

T

Parameters

NameDescriptionDefault
component

Component instance to append.

—

insertPrefab<T extends unknown[]>(components: [...T[]]): void

View source

Appends a component batch to this command’s payload.

The supplied array is spread into the existing payload, preserving its order and allowing multiple batches to be accumulated. The command keeps the component values, not the supplied array.

Type Parameters

T extends unknown[]

Parameters

NameDescriptionDefault
components

Components to append in order.

—