Compare commits

...

2 Commits

Author SHA1 Message Date
Serhii Snitsaruk 635ada23dd
Merge pull request #195 from limbonaut/fix-mapping-bug
BlackboardPlan: Fix mapping failing for NodePath variables with prefetch enabled
2024-08-14 21:15:33 +02:00
Serhii Snitsaruk e12beee51e
Fix mapping failing for NodePath variables with prefetch enabled 2024-08-14 20:34:56 +02:00
1 changed files with 5 additions and 6 deletions

View File

@ -395,10 +395,6 @@ inline void bb_add_var_dup_with_prefetch(const Ref<Blackboard> &p_blackboard, co
if (n != nullptr) { if (n != nullptr) {
var.set_value(n); var.set_value(n);
} else { } else {
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())); ERR_PRINT(vformat("BlackboardPlan: Prefetch failed for variable $%s with value: %s", p_name, p_var.get_value()));
var.set_value(Variant()); var.set_value(Variant());
} }
@ -418,12 +414,15 @@ Ref<Blackboard> BlackboardPlan::create_blackboard(Node *p_node, const Ref<Blackb
void BlackboardPlan::populate_blackboard(const Ref<Blackboard> &p_blackboard, bool overwrite, Node *p_node) { void BlackboardPlan::populate_blackboard(const Ref<Blackboard> &p_blackboard, bool overwrite, Node *p_node) {
ERR_FAIL_COND(p_node == nullptr && prefetch_nodepath_vars); ERR_FAIL_COND(p_node == nullptr && prefetch_nodepath_vars);
ERR_FAIL_COND(p_blackboard.is_null());
for (const Pair<StringName, BBVariable> &p : var_list) { for (const Pair<StringName, BBVariable> &p : var_list) {
if (p_blackboard->has_var(p.first) && !overwrite) { if (p_blackboard->has_var(p.first) && !overwrite) {
continue; continue;
} }
bb_add_var_dup_with_prefetch(p_blackboard, p.first, p.second, prefetch_nodepath_vars, p_node); bool has_mapping = parent_scope_mapping.has(p.first);
if (parent_scope_mapping.has(p.first)) { bool do_prefetch = !has_mapping && prefetch_nodepath_vars;
bb_add_var_dup_with_prefetch(p_blackboard, p.first, p.second, do_prefetch, p_node);
if (has_mapping) {
StringName target_var = parent_scope_mapping[p.first]; StringName target_var = parent_scope_mapping[p.first];
if (target_var != StringName()) { if (target_var != StringName()) {
ERR_CONTINUE_MSG(p_blackboard->get_parent() == nullptr, vformat("BlackboardPlan: Cannot link variable $%s to parent scope because the parent scope is not set.", p.first)); ERR_CONTINUE_MSG(p_blackboard->get_parent() == nullptr, vformat("BlackboardPlan: Cannot link variable $%s to parent scope because the parent scope is not set.", p.first));