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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(physics): retain edits made to inactive 2d bodies
yhh35e204625f6a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 45eaff59b..858f190d5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ published separately; it ships inside the editor.### Fixed+- **Inactive 2D bodies retain pending collider and body edits.** Physics reconciliation tracks the last synchronization of each body, so changes made while a parent or entity is inactive are applied on reactivation instead of being skipped by another body's newer global synchronization. Collider enable flags and rigid-body properties update in place, preserving the body and its existing simulation state.+- **Paused sprites refresh replaced animation clips.** A sprite that has already applied a clip follows a newly published clip while paused, updating its displayed frame without advancing the frame index or timer or firing playback events. Unchanged paused frames avoid component writes, and an initially paused animator still leaves the authored sprite untouched until playback or an explicit frame selection.- **Empty and collapsed scroll views keep finite scrollbar geometry.** Thumb sizing handles zero content without dividing by zero and clamps the minimum thumb length to the available track. Clearing a list or collapsing its viewport no longer writes Infinity or NaN into native UI nodes, and tiny viewports keep their thumbs inside the track before normal sizing resumes on restore.diff --git a/sdk/src/physics/PhysicsSystem.ts b/sdk/src/physics/PhysicsSystem.tsindex 045ff7d70..6055a3d9f 100644--- a/sdk/src/physics/PhysicsSystem.ts+++ b/sdk/src/physics/PhysicsSystem.ts@@ -610,6 +610,8 @@ interface CachedBodyProps {enabled: boolean;/** Bitmask of present collider components — drives shape rebuild on change. */colliderSig: number;+ /** Last sync of this body; inactive entities retain edits until reactivation. */+ syncedTick: number;}// The collider component types, in shape-add order. Their index is a stable bit@@ -805,6 +807,7 @@ export function registerPhysics2DSystem(bullet: rb.bullet,enabled: true,colliderSig: colliderSignature(world, entity),+ syncedTick: world.getWorldTick(),});if (rb.bodyType === BodyType.Kinematic) kinematicEntities.add(entity);if (rb.bodyType === BodyType.Static) {@@ -823,7 +826,7 @@ export function registerPhysics2DSystem(}// 2. body properties.- if (world.isChangedSince(entity, RigidBody2D, lastEntitySyncTick) &&+ if (world.isChangedSince(entity, RigidBody2D, cached.syncedTick) &&(cached.bodyType !== rb.bodyType ||cached.gravityScale !== rb.gravityScale ||cached.linearDamping !== rb.linearDamping ||@@ -847,7 +850,7 @@ export function registerPhysics2DSystem(// or any collider's fields change (body + velocity preserved).const sig = colliderSignature(world, entity);if (sig !== cached.colliderSig ||- collidersChangedSince(world, entity, lastEntitySyncTick)) {+ collidersChangedSince(world, entity, cached.syncedTick)) {module._physics_clearShapes(entity);addShapeForEntity(world, module, entity, config.collisionLayerMasks);cached.colliderSig = sig;@@ -865,6 +868,7 @@ export function registerPhysics2DSystem(else staticPoses.set(entity, { x: NaN, y: NaN, angle: NaN, parent });parentedBodies.delete(entity);} else staticPoses.delete(entity);+ cached.syncedTick = world.getWorldTick();}// Activity filtering removes descendants from the query too.diff --git a/sdk/tests/physics-activity-wasm.test.ts b/sdk/tests/physics-activity-wasm.test.tsindex d4c78a04a..9e2379682 100644--- a/sdk/tests/physics-activity-wasm.test.ts+++ b/sdk/tests/physics-activity-wasm.test.ts@@ -15,6 +15,39 @@ describe.skipIf(!HAS_WASM || !hasSideModule('physics'))('real Box2D hierarchy aclet engine: ESEngineModule;beforeAll(async () => { engine = await loadWasmModule(); });+ it('applies collider and body edits made while an ancestor is inactive', async () => {+ setDefaultContext(new AppContext());+ const registry = new engine.Registry() as unknown as CppRegistry;+ const app = App.new(); app.connectCpp(registry, engine);+ const physics = await loadSideModule<PhysicsWasmModule>('physics');+ const plugin = new Physics2DPlugin('', { gravity: { x: 0, y: -10 } }, async () => physics);+ plugin.build(app);+ try {+ await app.getResource(Physics2DRuntime).initPromise;+ const world = app.world, parent = world.spawn(), child = world.spawn();+ world.insert(parent, Transform);+ world.insert(child, Transform, { position: { x: 0, y: 100, z: 0 } });+ world.insert(child, RigidBody2D, { bodyType: 2, gravityScale: 0 });+ world.insert(child, BoxCollider2D); world.setParent(child, parent);+ await app.stepFrames(1, 1 / 30);+ expect(physics._physics_getShapeCount()).toBe(1);+ world.insert(parent, Disabled);+ await app.stepFrames(1, 1 / 30);+ world.update(child, BoxCollider2D, value => { value.enabled = false; });+ world.update(child, RigidBody2D, value => { value.gravityScale = 1; });+ await app.stepFrames(5, 1 / 30);+ const before = world.get(child, Transform).position.y;+ world.remove(parent, Disabled);+ await app.stepFrames(5, 1 / 30);+ expect(physics._physics_getShapeCount()).toBe(0);+ expect(world.get(child, Transform).position.y).toBeLessThan(before);+ expect(physics._physics_hasBody(child)).toBe(1);+ world.update(child, BoxCollider2D, value => { value.enabled = true; });+ await app.stepFrames(1, 1 / 30);+ expect(physics._physics_getShapeCount()).toBe(1);+ } finally { plugin.cleanup(); app.world.disconnectCpp(); registry.delete(); }+ });+it.each(['authored', 'native', 'body'] as const)('freezes and resumes a child without losing velocity (%s)', async (path) => {setDefaultContext(new AppContext());const registry = new engine.Registry() as unknown as CppRegistry;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 1e2964857..e440c33ae 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(physics): retain edits made to inactive 2d bodies':+ { note: 'Inactive 2D bodies retain pending collider and body edits.' },'fix(animation): refresh replaced clips on paused sprites':{ note: 'Paused sprites refresh replaced animation clips.' },'fix(ui): bound scrollbar geometry for empty viewports':