Skip to content

Fix init_physics_transform running twice and breaking scene hierarchies#873

Merged
Jondolf merged 2 commits into
mainfrom
fix-cursed-transform-bug
Oct 21, 2025
Merged

Fix init_physics_transform running twice and breaking scene hierarchies#873
Jondolf merged 2 commits into
mainfrom
fix-cursed-transform-bug

Conversation

@Jondolf

@Jondolf Jondolf commented Oct 21, 2025

Copy link
Copy Markdown
Member

Objective

The init_physics_transform hook can fail for scenes, because hierarchies may not be finalized in hooks (see bevyengine/bevy#18671). This normally doesn't actually cause problems, but in a very specific case where an entity has both a RigidBody and Collider (causing init_physics_transform to be called twice) in a hierarchy, and the insertion of one of the components is deferred such that the hierarchy is finalized for that one but not the other, the computed global transforms will end up being wrong. Yeah.

Solution

For now, just avoid calling init_physics_transform twice by checking if the entity has a RigidBody for colliders.

Additionally, only run transform_to_position logic for Position and Rotation if they were not just added, to avoid using the invalid values. Propagation will fix things up later.

Testing

The physics_avian example from bevy_trenchbroom, adding a RigidBody for the brushes.

@Jondolf Jondolf added this to the 0.4.1 milestone Oct 21, 2025
@Jondolf Jondolf added C-Bug Something isn't working P-Regression Behaviour that was working before is now worse or broken.Add a test for this! A-Transform Relates to transforms or physics positions labels Oct 21, 2025
@Jondolf Jondolf enabled auto-merge (squash) October 21, 2025 21:20
@Jondolf Jondolf merged commit 081d2de into main Oct 21, 2025
6 checks passed
@Jondolf Jondolf deleted the fix-cursed-transform-bug branch October 21, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Transform Relates to transforms or physics positions C-Bug Something isn't working P-Regression Behaviour that was working before is now worse or broken.Add a test for this!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant