CloneCommand

View source

ExtendsCommand

Builds a deferred clone of an entity hierarchy.

CloneCommand.create walks the source root and its descendants, allocates an empty clone handle for each entity immediately, and stores one SpawnCommand for each handle. The component insertions remain deferred until CloneCommand#execute runs those child commands in source-hierarchy order. The cloned root handle is available through CloneCommand#entity as soon as the command is created.

Examples

const command = CloneCommand.create(world, root)
command.execute(world)

const clonedRoot = command.entity

Constructor


constructor(commands: SpawnCommand[])

View source

Creates a clone command from child spawn commands.

The commands are stored in the supplied order. At least one command is required, and the first command’s entity is exposed as the cloned root. Use CloneCommand.create to build the commands from a world hierarchy.

Parameters

NameDescriptionDefault
commands

Child commands in hierarchy order.

—

Properties


readonlycommands: SpawnCommand[]

View source

Child spawn commands in source-hierarchy traversal order.

Each command targets an already allocated clone handle and contains the cloned components for the corresponding source entity.

Methods


staticcreate(world: World, entity: EntityHandle): CloneCommand

View source

Builds a clone command for an entity and all of its descendants.

The source must exist. The root and descendants are collected in relationship traversal order. World#spawn then allocates one empty entity for each source, and a SpawnCommand is stored for each handle; those component insertions do not happen until CloneCommand#execute runs.

Each registered component is copied with its registered clone method. EntityHandle and Children components are omitted. The The root’s Parent component keeps its original parent. Descendant Parent components are remapped to the corresponding cloned entities. Registered map methods receive the complete source-to-clone entity map, so other entity references can be remapped as well. When hierarchy hooks are installed, the inserted Parent components rebuild the cloned Children relationships.

Components without a registry entry or without a registered clone method are skipped with a warning. If setup throws after clone handles have been recorded, CloneCommand.create despawns each handle in the child-command list and does not rethrow that error. It then constructs a CloneCommand from that list; if no child command was added, the constructor’s non-empty-list assertion is raised.

Parameters

NameDescriptionDefault
world

World containing the source hierarchy and type registry.

—
entity

Root entity to clone.

—

Returns

Command containing the allocated clone hierarchy.

execute(world: World): void

View source

Executes every child SpawnCommand in hierarchy order.

Component insertion is delegated to each child command. This method does not allocate additional handles or rebuild the component payload.

Parameters

NameDescriptionDefault
world

World in which the clone handles were allocated.

—