diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 634ef9cbd2f..4d8d5d07705 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -258,6 +258,13 @@ void RayCast2D::remove_exception(const Object *p_object) { void RayCast2D::clear_exceptions() { exclude.clear(); + + if (exclude_parent_body && is_inside_tree()) { + CollisionObject2D *parent = Object::cast_to(get_parent()); + if (parent) { + exclude.insert(parent->get_rid()); + } + } } void RayCast2D::set_collide_with_areas(bool p_clip) { diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 610eb8d7e50..06e0d2d1340 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -256,6 +256,13 @@ void RayCast::remove_exception(const Object *p_object) { void RayCast::clear_exceptions() { exclude.clear(); + + if (exclude_parent_body && is_inside_tree()) { + CollisionObject *parent = Object::cast_to(get_parent()); + if (parent) { + exclude.insert(parent->get_rid()); + } + } } void RayCast::set_collide_with_areas(bool p_clip) {