diff --git a/blackboard/blackboard.h b/blackboard/blackboard.h index 49288e1..5758cfb 100644 --- a/blackboard/blackboard.h +++ b/blackboard/blackboard.h @@ -49,6 +49,7 @@ public: Variant get_var(const StringName &p_name, const Variant &p_default = Variant(), bool p_complain = true) const; void set_var(const StringName &p_name, const Variant &p_value); bool has_var(const StringName &p_name) const; + _FORCE_INLINE_ bool has_local_var(const StringName &p_name) const { return data.has(p_name); } void erase_var(const StringName &p_name); void clear() { data.clear(); } TypedArray list_vars() const; diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 7c61f8d..fa0234a 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -416,7 +416,7 @@ void BlackboardPlan::populate_blackboard(const Ref &p_blackboard, bo ERR_FAIL_COND(p_node == nullptr && prefetch_nodepath_vars); ERR_FAIL_COND(p_blackboard.is_null()); for (const Pair &p : var_list) { - if (p_blackboard->has_var(p.first) && !overwrite) { + if (p_blackboard->has_local_var(p.first) && !overwrite) { continue; } bool has_mapping = parent_scope_mapping.has(p.first); diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 6fd6ca5..75593e9 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -183,6 +183,7 @@ void BTPlayer::_notification(int p_notification) { blackboard = Ref(memnew(Blackboard)); } if (blackboard_plan.is_valid()) { + // Don't overwrite existing blackboard values as they may be initialized from code. blackboard_plan->populate_blackboard(blackboard, false, this); } if (behavior_tree.is_valid()) { diff --git a/hsm/limbo_state.cpp b/hsm/limbo_state.cpp index 972970d..e02ed92 100644 --- a/hsm/limbo_state.cpp +++ b/hsm/limbo_state.cpp @@ -95,7 +95,8 @@ void LimboState::_initialize(Node *p_agent, const Ref &p_blackboard) blackboard = p_blackboard; } if (blackboard_plan.is_valid() && !blackboard_plan->is_empty()) { - blackboard_plan->populate_blackboard(blackboard, true, this); + // Don't overwrite existing blackboard values as they may be initialized from code. + blackboard_plan->populate_blackboard(blackboard, false, this); } _setup();