Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(ecs): compose transforms through transformless groups

yhhf568396aaa0f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f154e09fd..62a0358cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Transformless hierarchy groups preserve child world poses.** A grouping entity without its own Transform no longer stops composition of its descendants. Root groups start from identity, intermediate groups carry the ancestor matrix through, and dirty propagation and traversal guards continue through those nodes.
+
- **Tilemap activity preserves painted data and owns generated collision.** Disabling a layer or its ancestor retains its chunks and derived layers. Runtime colliders inherit the map's movement and activity, remain outside saved scenes, and resume with their existing identities; inactive tile animations stop advancing.
- **Static 2D bodies follow authored transforms and parent movement.** Box2D updates changed static poses in place, preserving bodies and shapes without repeating writes for unchanged poses. Initial body creation composes the hierarchy first, and parented static bodies no longer force dynamic-body writeback out of its batch path.
diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hpp
index c559e6392..e961162b9 100644
--- a/src/esengine/ecs/TransformSystem.hpp
+++ b/src/esengine/ecs/TransformSystem.hpp
@@ -210,6 +210,15 @@ private:
}
});
+ if (have_children_) {
+ const glm::mat4 identity{1.0f};
+ registry.eachLive<Children>([&registry, this, &identity](Entity entity, Children& children) {
+ if (registry.has<Transform>(entity) || registry.has<Parent>(entity) || !visitOnce(entity)) return;
+ if (have_dirty_ && registry.has<TransformDirty>(entity)) dirty_to_clear_.push_back(entity);
+ for (Entity child : children.entities) updateEntityTransform(registry, child, identity, true);
+ });
+ }
+
for (Entity e : dirty_to_clear_) {
if (registry.has<TransformDirty>(e)) {
registry.remove<TransformDirty>(e);
@@ -260,11 +269,12 @@ private:
// growth. Per-composition stamps bound corrupt duplicate/cyclic links.
for (;;) {
auto* transform = registry.tryGet<Transform>(task.entity);
- if (transform && visitOnce(task.entity)) {
+ if (registry.valid(task.entity) && visitOnce(task.entity)) {
const bool localDirty = have_dirty_ && registry.has<TransformDirty>(task.entity);
const bool dirty = task.parentDirty || localDirty;
- const bool keepStatic = have_static_ && registry.has<TransformStatic>(task.entity) && !dirty;
- if (!keepStatic) {
+ const bool keepStatic = transform && have_static_ && registry.has<TransformStatic>(task.entity) && !dirty;
+ const glm::mat4* childMatrix = task.parentMatrix;
+ if (transform && !keepStatic) {
const auto matrix = *task.parentMatrix * math::compose(transform->position, transform->rotation, transform->scale);
if (changedOut_) {
++visited_;
@@ -272,8 +282,9 @@ private:
}
transform->cachedMatrix_ = matrix;
transform->decomposed_ = false;
- if (localDirty) dirty_to_clear_.push_back(task.entity);
}
+ if (localDirty) dirty_to_clear_.push_back(task.entity);
+ if (transform) childMatrix = &transform->cachedMatrix_;
if (auto* children = registry.tryGet<Children>(task.entity)) {
const auto& list = children->entities;
// Descend directly into the first child. Only siblings need a
@@ -281,10 +292,10 @@ private:
for (usize i = list.size(); i > 1; --i) {
// Transform storage is stable throughout composition; borrow
// its cache rather than copying a matrix into every task.
- pending_.push_back({list[i - 1], &transform->cachedMatrix_, keepStatic ? false : dirty});
+ pending_.push_back({list[i - 1], childMatrix, keepStatic ? false : dirty});
}
if (!list.empty()) {
- task = {list[0], &transform->cachedMatrix_, keepStatic ? false : dirty};
+ task = {list[0], childMatrix, keepStatic ? false : dirty};
continue;
}
}
diff --git a/tests/ecs/test_transform_traversal.cpp b/tests/ecs/test_transform_traversal.cpp
index 366ff449f..cc390b43d 100644
--- a/tests/ecs/test_transform_traversal.cpp
+++ b/tests/ecs/test_transform_traversal.cpp
@@ -4,6 +4,31 @@
using namespace esengine;
using namespace esengine::ecs;
+TEST_CASE("transformless grouping nodes preserve descendant composition") {
+ Registry r; TransformSystem system;
+ const auto root = r.create(), group = r.create(), child = r.create();
+ r.emplace<Transform>(child).position.x = 5;
+ setParent(r, child, group);
+ SUBCASE("grouping root") {
+ system.ensureComposed(r);
+ r.get<Transform>(child).ensureDecomposed();
+ CHECK(r.get<Transform>(child).worldPosition.x == doctest::Approx(5));
+ }
+ SUBCASE("group between transformed ancestors and descendants") {
+ r.emplace<Transform>(root).position.x = 10;
+ r.get<Transform>(root).scale.x = 2;
+ setParent(r, group, root);
+ system.ensureComposed(r);
+ r.get<Transform>(child).ensureDecomposed();
+ CHECK(r.get<Transform>(child).worldPosition.x == doctest::Approx(20));
+ r.get<Transform>(root).position.x = 30;
+ r.emplace<TransformDirty>(root);
+ invalidateTransformComposition(); system.ensureComposed(r);
+ r.get<Transform>(child).ensureDecomposed();
+ CHECK(r.get<Transform>(child).worldPosition.x == doctest::Approx(40));
+ }
+}
+
TEST_CASE("valid deep hierarchies compose every descendant") {
Registry r; TransformSystem system;
Entity parent = INVALID_ENTITY, leaf;
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index bbfbaa797..b0e3e1849 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(ecs): compose transforms through transformless groups':
+ { note: 'Transformless hierarchy groups preserve child world poses.' },
'fix(tilemap): preserve inactive layers and own runtime colliders':
{ note: 'Tilemap activity preserves painted data and owns generated collision.' },
'fix(physics): synchronize static body transforms in place':