diff --git a/blackboard/blackboard.cpp b/blackboard/blackboard.cpp index 820b7b1..db43265 100644 --- a/blackboard/blackboard.cpp +++ b/blackboard/blackboard.cpp @@ -74,8 +74,7 @@ void Blackboard::unbind_var(const StringName &p_name) { data[p_name].unbind(); } -void Blackboard::add_var(const StringName &p_name, const BBVariable &p_var) { - ERR_FAIL_COND(data.has(p_name)); +void Blackboard::assign_var(const StringName &p_name, const BBVariable &p_var) { data.insert(p_name, p_var); } diff --git a/blackboard/blackboard.h b/blackboard/blackboard.h index 0e8d7cb..2b55396 100644 --- a/blackboard/blackboard.h +++ b/blackboard/blackboard.h @@ -54,7 +54,7 @@ public: void bind_var_to_property(const StringName &p_name, Object *p_object, const StringName &p_property); void unbind_var(const StringName &p_name); - void add_var(const StringName &p_name, const BBVariable &p_var); + void assign_var(const StringName &p_name, const BBVariable &p_var); // TODO: Add serialization API. }; diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 8d85512..7708088 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -284,14 +284,16 @@ inline void bb_add_var_dup_with_prefetch(const Ref &p_blackboard, co if (n != nullptr) { var.set_value(n); } else { - // Print error only if the variable is not present (it can be initialized by the user or in the parent scope). - if (!p_blackboard->has_var(p_name)) { - ERR_PRINT(vformat("BlackboardPlan: Prefetch failed for variable $%s with value: %s", p_name, p_var.get_value())); + if (p_blackboard->has_var(p_name)) { + // Not adding: Assuming variable was initialized by the user or in the parent scope. + return; } + ERR_PRINT(vformat("BlackboardPlan: Prefetch failed for variable $%s with value: %s", p_name, p_var.get_value())); + var.set_value(Variant()); } - p_blackboard->add_var(p_name, var); + p_blackboard->assign_var(p_name, var); } else { - p_blackboard->add_var(p_name, p_var.duplicate()); + p_blackboard->assign_var(p_name, p_var.duplicate()); } }