From ce1867be7a62dc7ed0b485e5d0aeaed701544649 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Fri, 2 Aug 2024 10:07:42 +0200 Subject: [PATCH] Fix error if `changed` signal is already connected to a BBParam in a bunch of tasks --- bt/tasks/blackboard/bt_check_var.cpp | 5 +++-- bt/tasks/blackboard/bt_set_var.cpp | 5 +++-- bt/tasks/scene/bt_await_animation.cpp | 5 +++-- bt/tasks/scene/bt_check_agent_property.cpp | 5 +++-- bt/tasks/scene/bt_pause_animation.cpp | 5 +++-- bt/tasks/scene/bt_play_animation.cpp | 5 +++-- bt/tasks/scene/bt_set_agent_property.cpp | 5 +++-- bt/tasks/scene/bt_stop_animation.cpp | 5 +++-- bt/tasks/utility/bt_call_method.cpp | 5 +++-- bt/tasks/utility/bt_evaluate_expression.cpp | 5 +++-- 10 files changed, 30 insertions(+), 20 deletions(-) diff --git a/bt/tasks/blackboard/bt_check_var.cpp b/bt/tasks/blackboard/bt_check_var.cpp index 14962dc..98f092e 100644 --- a/bt/tasks/blackboard/bt_check_var.cpp +++ b/bt/tasks/blackboard/bt_check_var.cpp @@ -24,8 +24,9 @@ void BTCheckVar::set_check_type(LimboUtility::CheckType p_check_type) { void BTCheckVar::set_value(const Ref &p_value) { value = p_value; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && value.is_valid() && + !value->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + value->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/blackboard/bt_set_var.cpp b/bt/tasks/blackboard/bt_set_var.cpp index 4b44d1d..9b6bc77 100644 --- a/bt/tasks/blackboard/bt_set_var.cpp +++ b/bt/tasks/blackboard/bt_set_var.cpp @@ -48,8 +48,9 @@ void BTSetVar::set_variable(const StringName &p_variable) { void BTSetVar::set_value(const Ref &p_value) { value = p_value; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && value.is_valid() && + !value->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + value->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_await_animation.cpp b/bt/tasks/scene/bt_await_animation.cpp index a511cdf..a2fe9cb 100644 --- a/bt/tasks/scene/bt_await_animation.cpp +++ b/bt/tasks/scene/bt_await_animation.cpp @@ -16,8 +16,9 @@ void BTAwaitAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid() && + !animation_player_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + animation_player_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_check_agent_property.cpp b/bt/tasks/scene/bt_check_agent_property.cpp index 7ac0c4d..8d64d6d 100644 --- a/bt/tasks/scene/bt_check_agent_property.cpp +++ b/bt/tasks/scene/bt_check_agent_property.cpp @@ -24,8 +24,9 @@ void BTCheckAgentProperty::set_check_type(LimboUtility::CheckType p_check_type) void BTCheckAgentProperty::set_value(Ref p_value) { value = p_value; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && value.is_valid() && + !value->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + value->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_pause_animation.cpp b/bt/tasks/scene/bt_pause_animation.cpp index 4f1dd3c..71f88f1 100644 --- a/bt/tasks/scene/bt_pause_animation.cpp +++ b/bt/tasks/scene/bt_pause_animation.cpp @@ -16,8 +16,9 @@ void BTPauseAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid() && + !animation_player_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + animation_player_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_play_animation.cpp b/bt/tasks/scene/bt_play_animation.cpp index f373e5f..c021401 100644 --- a/bt/tasks/scene/bt_play_animation.cpp +++ b/bt/tasks/scene/bt_play_animation.cpp @@ -16,8 +16,9 @@ void BTPlayAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid() && + !animation_player_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + animation_player_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_set_agent_property.cpp b/bt/tasks/scene/bt_set_agent_property.cpp index 600e138..a182391 100644 --- a/bt/tasks/scene/bt_set_agent_property.cpp +++ b/bt/tasks/scene/bt_set_agent_property.cpp @@ -19,8 +19,9 @@ void BTSetAgentProperty::set_property(StringName p_prop) { void BTSetAgentProperty::set_value(Ref p_value) { value = p_value; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && value.is_valid()) { - value->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && value.is_valid() && + !value->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + value->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/scene/bt_stop_animation.cpp b/bt/tasks/scene/bt_stop_animation.cpp index 0bc247b..d64e079 100644 --- a/bt/tasks/scene/bt_stop_animation.cpp +++ b/bt/tasks/scene/bt_stop_animation.cpp @@ -16,8 +16,9 @@ void BTStopAnimation::set_animation_player(Ref p_animation_player) { animation_player_param = p_animation_player; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid()) { - animation_player_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && animation_player_param.is_valid() && + !animation_player_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + animation_player_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/utility/bt_call_method.cpp b/bt/tasks/utility/bt_call_method.cpp index f559d2e..0b46804 100644 --- a/bt/tasks/utility/bt_call_method.cpp +++ b/bt/tasks/utility/bt_call_method.cpp @@ -28,8 +28,9 @@ void BTCallMethod::set_method(const StringName &p_method_name) { void BTCallMethod::set_node_param(const Ref &p_object) { node_param = p_object; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid()) { - node_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid() && + !node_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + node_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } } diff --git a/bt/tasks/utility/bt_evaluate_expression.cpp b/bt/tasks/utility/bt_evaluate_expression.cpp index 21ad51e..b175a9f 100644 --- a/bt/tasks/utility/bt_evaluate_expression.cpp +++ b/bt/tasks/utility/bt_evaluate_expression.cpp @@ -29,8 +29,9 @@ void BTEvaluateExpression::set_expression_string(const String &p_expression_stri void BTEvaluateExpression::set_node_param(Ref p_object) { node_param = p_object; emit_changed(); - if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid()) { - node_param->connect(LW_NAME(changed), Callable(this, LW_NAME(emit_changed))); + if (Engine::get_singleton()->is_editor_hint() && node_param.is_valid() && + !node_param->is_connected(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed))) { + node_param->connect(LW_NAME(changed), callable_mp((Resource *)this, &Resource::emit_changed)); } }