diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 6916f832d03..c9668f44790 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -50,7 +50,9 @@ void CollisionObject2D::_notification(int p_what) { } if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { - RID space = get_world_2d()->get_space(); + Ref world_ref = get_world_2d(); + ERR_FAIL_COND(!world_ref.is_valid()); + RID space = world_ref->get_space(); if (area) { PhysicsServer2D::get_singleton()->area_set_space(rid, space); } else { diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index 814ed5c2a77..9958d6d3d55 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -64,7 +64,9 @@ void CollisionObject3D::_notification(int p_what) { } if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) { - RID space = get_world_3d()->get_space(); + Ref world_ref = get_world_3d(); + ERR_FAIL_COND(!world_ref.is_valid()); + RID space = world_ref->get_space(); if (area) { PhysicsServer3D::get_singleton()->area_set_space(rid, space); } else {