Enable binding in BehaviorTree-owned blackboard plan

This commit is contained in:
Serhii Snitsaruk 2024-11-11 10:10:20 +01:00
parent 4cac6276aa
commit 0b3b11a383
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
1 changed files with 10 additions and 3 deletions

View File

@ -479,7 +479,7 @@ void BlackboardPlan::populate_blackboard(const Ref<Blackboard> &p_blackboard, bo
#endif #endif
continue; continue;
} }
bool is_bound = property_bindings.has(p.first); bool is_bound = has_property_binding(p.first) || (is_derived() && get_base_plan()->has_property_binding(p.first));
bool has_mapping = parent_scope_mapping.has(p.first); bool has_mapping = parent_scope_mapping.has(p.first);
bool do_prefetch = !is_bound && !has_mapping && prefetch_nodepath_vars; bool do_prefetch = !is_bound && !has_mapping && prefetch_nodepath_vars;
@ -505,12 +505,19 @@ void BlackboardPlan::populate_blackboard(const Ref<Blackboard> &p_blackboard, bo
} }
} else if (is_bound) { } else if (is_bound) {
// Bind variable to a property of a scene node. // Bind variable to a property of a scene node.
NodePath binding_path = property_bindings[p.first]; NodePath binding_path;
Node *binding_root;
if (has_property_binding(p.first)) {
binding_path = property_bindings[p.first];
binding_root = p_prefetch_root;
} else {
binding_path = get_base_plan()->property_bindings[p.first];
binding_root = p_prefetch_root_for_base_plan;
}
ERR_CONTINUE_MSG(binding_path.get_subname_count() != 1, vformat("BlackboardPlan: Can't bind variable %s using property path that contains multiple sub-names: %s", LimboUtility::get_singleton()->decorate_var(p.first), binding_path)); ERR_CONTINUE_MSG(binding_path.get_subname_count() != 1, vformat("BlackboardPlan: Can't bind variable %s using property path that contains multiple sub-names: %s", LimboUtility::get_singleton()->decorate_var(p.first), binding_path));
NodePath node_path{ binding_path.get_concatenated_names() }; NodePath node_path{ binding_path.get_concatenated_names() };
StringName prop_name = binding_path.get_subname(0); StringName prop_name = binding_path.get_subname(0);
// TODO: Implement binding for base plan as well. // TODO: Implement binding for base plan as well.
Node *binding_root = p_prefetch_root;
Node *n = binding_root->get_node_or_null(node_path); Node *n = binding_root->get_node_or_null(node_path);
ERR_CONTINUE_MSG(n == nullptr, vformat("BlackboardPlan: Binding failed for variable %s using property path: %s", LimboUtility::get_singleton()->decorate_var(p.first), binding_path)); ERR_CONTINUE_MSG(n == nullptr, vformat("BlackboardPlan: Binding failed for variable %s using property path: %s", LimboUtility::get_singleton()->decorate_var(p.first), binding_path));
var.bind(n, prop_name); var.bind(n, prop_name);