From 0b3b11a38385da4f391ad0bb4f01800902b481d4 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 11 Nov 2024 10:10:20 +0100 Subject: [PATCH] Enable binding in BehaviorTree-owned blackboard plan --- blackboard/blackboard_plan.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index e617160..bc054d4 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -479,7 +479,7 @@ void BlackboardPlan::populate_blackboard(const Ref &p_blackboard, bo #endif 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 do_prefetch = !is_bound && !has_mapping && prefetch_nodepath_vars; @@ -505,12 +505,19 @@ void BlackboardPlan::populate_blackboard(const Ref &p_blackboard, bo } } else if (is_bound) { // 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)); NodePath node_path{ binding_path.get_concatenated_names() }; StringName prop_name = binding_path.get_subname(0); // TODO: Implement binding for base plan as well. - Node *binding_root = p_prefetch_root; 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)); var.bind(n, prop_name);