diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 4ae9b37c21d..f7e4c5faf0a 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -39,6 +39,9 @@ void CollisionShape2D::_add_to_collision_object(Object *p_obj) { + if (unparenting) + return; + CollisionObject2D *co = p_obj->cast_to(); ERR_FAIL_COND(!co); co->add_shape(shape,get_transform()); @@ -189,7 +192,10 @@ void CollisionShape2D::_notification(int p_what) { rect=rect.grow(3); } break; - + case NOTIFICATION_UNPARENTED: { + unparenting = true; + _update_parent(); + } break; } } @@ -245,4 +251,5 @@ CollisionShape2D::CollisionShape2D() { rect=Rect2(-Point2(10,10),Point2(20,20)); trigger=false; + unparenting = false; } diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h index 2e2023f54d0..a89af49a348 100644 --- a/scene/2d/collision_shape_2d.h +++ b/scene/2d/collision_shape_2d.h @@ -38,7 +38,7 @@ class CollisionShape2D : public Node2D { Ref shape; Rect2 rect; bool trigger; - + bool unparenting; void _shape_changed(); protected: