Fix SoftBody3D
pinned points breaking when reloading scene
#86310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #86308.
The issue is that
SoftBody3D::_add_pinned_point()
usespinned_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 callingget_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 callingpin_point()
immediately inSoftBody3D::_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 topin_point()
when inside the tree and callingpin_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: