Class
SpawnCommand
View sourceExtendsCommand
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
View source
Properties
readonlyentity: EntityHandle
View sourceEntity to receive the accumulated component payload.
The handle is stored as supplied and is resolved only when
SpawnCommand#execute runs.
components: any[]
View sourceComponents passed to World#insert in insertion order.
SpawnCommand#insert and SpawnCommand#insertPrefab
append to this array; neither method changes the world.
Default: []
Methods
insert<T>(component: T): void
View sourceAppends 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.
insertPrefab<T extends unknown[]>(components: [...T[]]): void
View sourceAppends 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.
execute(world: World): void
View sourceApplies the queued insertion to a world.
Delegates to World#insert with the stored
SpawnCommand#entity and accumulated
SpawnCommand#components. The payload is not cleared, so
executing the same command again submits the same component values again.
