From a994bb4ad36070623149af9aad047cc8bb605609 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Mon, 11 Jan 2021 09:04:08 -0700 Subject: [PATCH] Fix collision shape update when changing shape properties This change does two things: 1. Properly update the internal shape data using _update_in_shape_owner when updating a shape (in 2D it was resetting one way collision) 2. Avoid unnecessary updates when calling set_shape with the same shape, which happens each time a shape property is modified (e.g shape.extents.x = ...) Fixes #45090 (cherry picked from commit 4b43cd17c5412f4cc4c67b6bb8de8717e7b2aff4) --- scene/2d/collision_polygon_2d.cpp | 2 ++ scene/2d/collision_shape_2d.cpp | 5 ++++- scene/3d/collision_shape.cpp | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index c2890b117a7..1c508ec77b2 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -205,6 +205,7 @@ void CollisionPolygon2D::set_polygon(const Vector &p_polygon) { if (parent) { _build_polygon(); + _update_in_shape_owner(); } update(); update_configuration_warning(); @@ -221,6 +222,7 @@ void CollisionPolygon2D::set_build_mode(BuildMode p_mode) { build_mode = p_mode; if (parent) { _build_polygon(); + _update_in_shape_owner(); } } diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 589dfa1492b..dfe69943582 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -147,7 +147,9 @@ void CollisionShape2D::_notification(int p_what) { } void CollisionShape2D::set_shape(const Ref &p_shape) { - + if (p_shape == shape) { + return; + } if (shape.is_valid()) shape->disconnect("changed", this, "_shape_changed"); shape = p_shape; @@ -157,6 +159,7 @@ void CollisionShape2D::set_shape(const Ref &p_shape) { if (shape.is_valid()) { parent->shape_owner_add_shape(owner_id, shape); } + _update_in_shape_owner(); } if (shape.is_valid()) diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape.cpp index 9e3e45326f9..9d8351f1a93 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape.cpp @@ -83,7 +83,6 @@ void CollisionShape::_notification(int p_what) { if (shape.is_valid()) { parent->shape_owner_add_shape(owner_id, shape); } - _update_in_shape_owner(); } } break; case NOTIFICATION_ENTER_TREE: { @@ -170,7 +169,9 @@ void CollisionShape::_bind_methods() { } void CollisionShape::set_shape(const Ref &p_shape) { - + if (p_shape == shape) { + return; + } if (!shape.is_null()) { shape->unregister_owner(this); shape->disconnect("changed", this, "_shape_changed");