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.

perf(physics): recompute parented membership with the reconcile, not per step

esengine68ac7a117da7
diff --git a/sdk/src/physics/PhysicsSystem.ts b/sdk/src/physics/PhysicsSystem.ts
index 30e269d76..bf829de9d 100644
--- a/sdk/src/physics/PhysicsSystem.ts
+++ b/sdk/src/physics/PhysicsSystem.ts
@@ -890,11 +890,15 @@ export function registerPhysicsSystem(
// Membership decides batch-vs-parented writeback; a runtime
// reparent of a live body would otherwise stay on the batch path
- // and get its world pose written as a local one. Refreshed per
- // fixed step, so a reparent takes effect on the next physics tick.
- for (const entity of trackedEntities) {
- if (world.has(entity, Parent)) parentedBodies.add(entity);
- else parentedBodies.delete(entity);
+ // and get its world pose written as a local one. Only gaining or
+ // losing a Parent changes the answer, and that is a structural
+ // edit, so this rides the reconcile gate rather than walking
+ // every body every step.
+ if (needReconcile) {
+ for (const entity of trackedEntities) {
+ if (world.has(entity, Parent)) parentedBodies.add(entity);
+ else parentedBodies.delete(entity);
+ }
}
},
{ name: 'PhysicsStepSystem' }