Skip to content

Commit

Permalink
Merge pull request #88947 from lawnjelly/fix_physics_platform_rid
Browse files Browse the repository at this point in the history
Fix physics platform crash
  • Loading branch information
akien-mga committed Mar 1, 2024
2 parents bd76372 + 0b1266b commit 7900597
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scene/3d/physics/character_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ bool CharacterBody3D::move_and_slide() {
excluded = (platform_wall_layers & platform_layer) == 0;
}
if (!excluded) {
//this approach makes sure there is less delay between the actual body velocity and the one we saved
PhysicsDirectBodyState3D *bs = PhysicsServer3D::get_singleton()->body_get_direct_state(platform_rid);
PhysicsDirectBodyState3D *bs = nullptr;

// We need to check the platform_rid object still exists before accessing.
// A valid RID is no guarantee that the object has not been deleted.
if (ObjectDB::get_instance(platform_object_id)) {
//this approach makes sure there is less delay between the actual body velocity and the one we saved
bs = PhysicsServer3D::get_singleton()->body_get_direct_state(platform_rid);
}

if (bs) {
Vector3 local_position = gt.origin - bs->get_transform().origin;
current_platform_velocity = bs->get_velocity_at_local_position(local_position);
Expand Down

0 comments on commit 7900597

Please sign in to comment.