Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SoftBody3D pinned points breaking when reloading scene #86310

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Fix SoftBody3D pinned points breaking when reloading scene #86310

merged 1 commit into from
Aug 16, 2024

Conversation

jirisvd
Copy link
Contributor

@jirisvd jirisvd commented Dec 18, 2023

Fixes #86308.

The issue is that SoftBody3D::_add_pinned_point() uses pinned_point->spatial_attachment->get_global_transform() to calculate the offset of the pinned point, but getting the global transform of the spatial attachment fails when it's not inside the tree. When calling get_tree().reload_current_scene(), the spatial attachment was not inside the tree when _add_pinned_point() was called, causing the bug described in #86308, as the offset calculation failed and the pinned points became displaced as a result.

I found that disabling the deferred call to SoftBody3D::pin_point() implemented in #71824 and instead calling pin_point() immediately in SoftBody3D::_set_property_pinned_points_attachment() got rid of this issue, but that broke the reparenting issue that motivated the deferred call in the first place.

By adding an is_inside_tree() condition and using the deferred call to pin_point() when inside the tree and calling pin_point() directly when outside of the tree, I managed to get it into a state where both the offset calculation issue (#86308) and the reparenting issue (#71785) are prevented.

Physics squad edit:

Copy link
Member

@rburing rburing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and confirmed this fixes the issues.

The direct code path is used when (re)loading/exporting the scene, and the deferred code path is used in the editor e.g. when reparenting.

@akien-mga akien-mga added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Aug 11, 2024
@akien-mga akien-mga merged commit 0c956e4 into godotengine:master Aug 16, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@jirisvd jirisvd deleted the fix-softbody-reload branch August 16, 2024 17:07
@akien-mga
Copy link
Member

Cherry-picked for 4.3.1.

@akien-mga akien-mga removed the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants