BTSubtree: Fix subtree blackboard plan is not property utilized
This commit is contained in:
parent
31db4b4543
commit
e50b00c70e
|
@ -11,6 +11,15 @@
|
|||
|
||||
#include "bt_new_scope.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();
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void BTNewScope::initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) {
|
||||
ERR_FAIL_COND(p_agent == nullptr);
|
||||
ERR_FAIL_COND(p_blackboard == nullptr);
|
||||
|
|
|
@ -26,7 +26,9 @@ private:
|
|||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) { blackboard_plan = p_plan; }
|
||||
virtual void _update_blackboard_plan() {}
|
||||
|
||||
void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan);
|
||||
Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; }
|
||||
|
||||
virtual Status _tick(double p_delta) override;
|
||||
|
|
|
@ -11,11 +11,27 @@
|
|||
|
||||
#include "bt_subtree.h"
|
||||
|
||||
void BTSubtree::set_subtree(const Ref<BehaviorTree> &p_value) {
|
||||
subtree = p_value;
|
||||
void BTSubtree::set_subtree(const Ref<BehaviorTree> &p_subtree) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (subtree.is_valid() && subtree->is_connected(LW_NAME(changed), callable_mp(this, &BTSubtree::_update_blackboard_plan))) {
|
||||
subtree->disconnect(LW_NAME(changed), callable_mp(this, &BTSubtree::_update_blackboard_plan));
|
||||
}
|
||||
if (p_subtree.is_valid()) {
|
||||
p_subtree->connect(LW_NAME(changed), callable_mp(this, &BTSubtree::_update_blackboard_plan));
|
||||
}
|
||||
}
|
||||
subtree = p_subtree;
|
||||
_update_blackboard_plan();
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void BTSubtree::_update_blackboard_plan() {
|
||||
if (get_blackboard_plan().is_null()) {
|
||||
set_blackboard_plan(Ref<BlackboardPlan>(memnew(BlackboardPlan)));
|
||||
}
|
||||
get_blackboard_plan()->set_base_plan(subtree.is_valid() ? subtree->get_blackboard_plan() : nullptr);
|
||||
}
|
||||
|
||||
String BTSubtree::_generate_name() {
|
||||
String s;
|
||||
if (subtree.is_null()) {
|
||||
|
@ -57,3 +73,11 @@ void BTSubtree::_bind_methods() {
|
|||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "subtree", PROPERTY_HINT_RESOURCE_TYPE, "BehaviorTree"), "set_subtree", "get_subtree");
|
||||
}
|
||||
|
||||
BTSubtree::~BTSubtree() {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (subtree.is_valid() && subtree->is_connected(LW_NAME(changed), callable_mp(this, &BTSubtree::_update_blackboard_plan))) {
|
||||
subtree->disconnect(LW_NAME(changed), callable_mp(this, &BTSubtree::_update_blackboard_plan));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ private:
|
|||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
virtual void _update_blackboard_plan() override;
|
||||
|
||||
virtual String _generate_name() override;
|
||||
virtual Status _tick(double p_delta) override;
|
||||
|
||||
|
@ -35,6 +37,9 @@ public:
|
|||
|
||||
virtual void initialize(Node *p_agent, const Ref<Blackboard> &p_blackboard) override;
|
||||
virtual PackedStringArray get_configuration_warnings() override;
|
||||
|
||||
BTSubtree() = default;
|
||||
~BTSubtree();
|
||||
};
|
||||
|
||||
#endif // BT_SUBTREE_H
|
||||
|
|
Loading…
Reference in New Issue