Fix issues with mapping in BTSubtree

This commit is contained in:
Serhii Snitsaruk 2024-05-14 19:47:05 +02:00
parent e43bc25d82
commit a1cdff2e2e
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
5 changed files with 22 additions and 11 deletions

View File

@ -28,7 +28,6 @@ bool BlackboardPlan::_set(const StringName &p_name, const Variant &p_value) {
// * Mapping
if (name_str.begins_with("mapping/")) {
StringName mapped_var_name = name_str.get_slicec('/', 1);
ERR_FAIL_COND_V(!has_var(mapped_var_name), false);
parent_scope_mapping[mapped_var_name] = p_value;
return true;
}
@ -382,7 +381,7 @@ Ref<Blackboard> BlackboardPlan::create_blackboard(Node *p_node, const Ref<Blackb
ERR_FAIL_COND_V(p_node == nullptr && prefetch_nodepath_vars, memnew(Blackboard));
Ref<Blackboard> bb = memnew(Blackboard);
bb->set_parent(p_parent_scope);
populate_blackboard(bb, false, p_node);
populate_blackboard(bb, true, p_node);
return bb;
}

View File

@ -48,7 +48,6 @@ void BehaviorTree::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
blackboard_plan->connect(LW_NAME(changed), callable_mp(this, &BehaviorTree::_plan_changed));
}
_set_editor_behavior_tree_hint();
_plan_changed();
}

View File

@ -11,28 +11,43 @@
#include "bt_new_scope.h"
#include "../../behavior_tree.h"
void BTNewScope::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
blackboard_plan = p_plan;
if (blackboard_plan.is_null()) {
blackboard_plan.instantiate();
}
_update_blackboard_plan();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
callable_mp(this, &BTNewScope::_set_parent_scope_plan_from_bt).call_deferred();
}
#endif // TOOLS_ENABLED
emit_changed();
}
void BTNewScope::_set_parent_scope_plan_from_bt() {
ERR_FAIL_NULL(get_blackboard_plan());
Ref<BehaviorTree> bt = get_root()->editor_get_behavior_tree();
ERR_FAIL_NULL(bt);
get_blackboard_plan()->set_parent_scope_plan(bt->get_blackboard_plan());
}
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard, Node *p_scene_root) {
ERR_FAIL_COND(p_agent == nullptr);
ERR_FAIL_COND(p_blackboard == nullptr);
Ref<Blackboard> bb;
if (blackboard_plan.is_valid()) {
bb = blackboard_plan->create_blackboard(p_agent);
bb = blackboard_plan->create_blackboard(p_agent, p_blackboard);
} else {
bb = Ref<Blackboard>(memnew(Blackboard));
bb->set_parent(p_blackboard);
}
bb->set_parent(p_blackboard);
BTDecorator::initialize(p_agent, bb, p_scene_root);
}

View File

@ -23,6 +23,8 @@ class BTNewScope : public BTDecorator {
private:
Ref<BlackboardPlan> blackboard_plan;
void _set_parent_scope_plan_from_bt();
protected:
static void _bind_methods();

View File

@ -30,10 +30,6 @@ void BTSubtree::_update_blackboard_plan() {
set_blackboard_plan(Ref<BlackboardPlan>(memnew(BlackboardPlan)));
}
get_blackboard_plan()->set_base_plan(subtree.is_valid() ? subtree->get_blackboard_plan() : nullptr);
#ifdef TOOLS_ENABLED
get_blackboard_plan()->set_parent_scope_plan(get_root()->editor_get_behavior_tree()->get_blackboard_plan());
#endif // TOOLS_ENABLED
}
String BTSubtree::_generate_name() {