diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2023-03-23 19:13:24 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 17:53:34 +0200 |
commit | 9573574788b0ab4b5707aaba34a81110864748e6 (patch) | |
tree | 088a3b803f860f6cf47dbd8d90257d8b3b83cd31 /scene/2d | |
parent | 58d8368481813398aab77717a59461c3b79e3a2d (diff) |
Port robust signal (dis)connection to ShapeCast2D
Ported from ShapeCast3D.
(cherry picked from commit 5bed055cdd5180b4c5d07f07a2a58644a3d1ffc2)
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/shape_cast_2d.cpp | 13 | ||||
-rw-r--r-- | scene/2d/shape_cast_2d.h | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/scene/2d/shape_cast_2d.cpp b/scene/2d/shape_cast_2d.cpp index bafb83361a..5b743e0b31 100644 --- a/scene/2d/shape_cast_2d.cpp +++ b/scene/2d/shape_cast_2d.cpp @@ -151,11 +151,18 @@ bool ShapeCast2D::is_enabled() const { } void ShapeCast2D::set_shape(const Ref<Shape2D> &p_shape) { + if (p_shape == shape) { + return; + } + if (shape.is_valid()) { + shape->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_shape_changed)); + } shape = p_shape; - if (p_shape.is_valid()) { - shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_redraw_shape)); + if (shape.is_valid()) { + shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_shape_changed)); shape_rid = shape->get_rid(); } + update_configuration_warnings(); queue_redraw(); } @@ -186,7 +193,7 @@ bool ShapeCast2D::get_exclude_parent_body() const { return exclude_parent_body; } -void ShapeCast2D::_redraw_shape() { +void ShapeCast2D::_shape_changed() { queue_redraw(); } diff --git a/scene/2d/shape_cast_2d.h b/scene/2d/shape_cast_2d.h index 8a62b799f8..a577c351fd 100644 --- a/scene/2d/shape_cast_2d.h +++ b/scene/2d/shape_cast_2d.h @@ -61,7 +61,7 @@ class ShapeCast2D : public Node2D { real_t collision_unsafe_fraction = 1.0; Array _get_collision_result() const; - void _redraw_shape(); + void _shape_changed(); protected: void _notification(int p_what); |