Skip to content

Add entity clone, component remove and reparent commands - #359

Merged
waynemwashuma merged 5 commits into
wimaengine:devfrom
waynemwashuma:reparent-commands
Aug 18, 2026
Merged

Add entity clone, component remove and reparent commands#359
waynemwashuma merged 5 commits into
wimaengine:devfrom
waynemwashuma:reparent-commands

Conversation

@waynemwashuma

@waynemwashuma waynemwashuma commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Objective

Introduces additional high-level entity commands for cloning entities, removing components, and reparenting entities while preserving their world transforms.

Solution

The new operations are implemented as dedicated commands and queued through the existing EntityCommands API.

Changes Made

  • Introduce EntityCommands.clone() creates a hierarchy-aware clone by traversing the source entity's descendants, cloning registered components and remapping entity relationships to the cloned hierarchy.
  • Introduce EntityCommands.reparent() recalculates an entity's local transform relative to its new parent before changing the Parent component. It handles both 2D and 3D transforms and prevents an entity from being reparented to itself or one of its descendants..
  • Introduce EntityCommands.remove() for removing a tuple of components from an entity.

Why This Approach

  • Entity mutations remain deferred through the existing command queue.
  • Cloning the hierarchy as a group allows parent-child relationships to be reconstructed using the cloned entity IDs.
  • Using TypeRegistry keeps component cloning extensible and avoids requiring individual component types to be handled explicitly.
  • Reparenting through inverse parent transforms preserves the entity's world-space transform while changing its local transform.
  • Dedicated commands keep the operations isolated and allow them to participate in the existing command execution pipeline.

Showcase

Before

Entities could be spawned and despawned through EntityCommands, but there was no command-level API for cloning, removing components or reparenting.

After

Entities can now be easily cloned, have components removed and be reparented:

const commands = new EntityCommands(world)

const clone = commands.clone(entity)

commands.remove(entity, [ComponentA, ComponentB])

commands.reparent(entity, parent)

Migration Guide

No migration required.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Aug 18, 2026
@waynemwashuma waynemwashuma added the type:enhancement New feature or request label Aug 18, 2026
@waynemwashuma
waynemwashuma merged commit e8cc4cb into wimaengine:dev Aug 18, 2026
7 checks passed
@waynemwashuma
waynemwashuma deleted the reparent-commands branch August 18, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant