Skip to content

Commit

Permalink
feat(transform): destroy child entities when parent is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
kuukitenshi committed Mar 3, 2025
1 parent a55164f commit a0b8158
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Entity destruction detection to observers (#1458, **@kuukitenshi**).

- Destroy child entities when parent entities are destroyed (#1418, **@kuukitenshi**).

## [v0.6.0] - 2025-02-10

Expand Down
4 changes: 2 additions & 2 deletions core/src/ecs/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Entity CommandBuffer::create()
void CommandBuffer::destroy(Entity entity)
{
std::lock_guard<std::mutex> lock(mMutex);

mCommands.emplace_back([entity](World& world) { world.destroy(entity); });
mCommands.emplace_back([entity](World& world) { world.destroy(entity);});
}

std::unordered_map<std::string, Entity> CommandBuffer::spawn(const Blueprint& blueprint, bool withName)
Expand Down
9 changes: 9 additions & 0 deletions engine/src/transform/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ void cubos::engine::transformPlugin(Cubos& cubos)
.without<LocalToParent>()
.call(addComponent<LocalToParent>);

cubos.observer("destroy childs when parent is destroyed")
.onDestroy()
.call([](Query<Entity, const ChildOf&, Entity> query, Commands cmds) {
for (auto [entity, childOf, child] : query)
{
cmds.destroy(child);
}
});

cubos.system("update LocalToParent's")
.tagged(transformUpdateTag)
.before(transformUpdatePropagateTag)
Expand Down

0 comments on commit a0b8158

Please sign in to comment.