Prevent using external resources for derived blackboard plans in `BTPlayer` and `BTState`

This commit is contained in:
Serhii Snitsaruk 2024-04-01 15:06:06 +02:00
parent d48daf2135
commit 302de87e32
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
5 changed files with 18 additions and 5 deletions

View File

@ -122,6 +122,7 @@ bool BlackboardPlan::_property_get_revert(const StringName &p_name, Variant &r_p
void BlackboardPlan::set_base_plan(const Ref<BlackboardPlan> &p_base) {
if (p_base == this) {
WARN_PRINT_ED("BlackboardPlan: Using same resource for derived blackboard plan is not supported.");
base.unref();
} else {
base = p_base;

View File

@ -86,7 +86,12 @@ void BTPlayer::set_behavior_tree(const Ref<BehaviorTree> &p_tree) {
}
void BTPlayer::set_blackboard_plan(const Ref<BlackboardPlan> &p_plan) {
blackboard_plan = p_plan;
if (p_plan.is_valid() && !RESOURCE_IS_BUILT_IN(p_plan)) {
WARN_PRINT_ED("BTPlayer: Using external resource for derived blackboard plan is not supported. Converted to built-in resource.");
blackboard_plan = p_plan->duplicate();
} else {
blackboard_plan = p_plan;
}
_update_blackboard_plan();
}

View File

@ -31,16 +31,22 @@ void BTState::set_behavior_tree(const Ref<BehaviorTree> &p_tree) {
if (p_tree.is_valid()) {
p_tree->connect(LW_NAME(changed), callable_mp(this, &BTState::_update_blackboard_plan));
}
behavior_tree = p_tree;
_update_blackboard_plan();
} else {
behavior_tree = p_tree;
}
behavior_tree = p_tree;
}
void BTState::_update_blackboard_plan() {
if (get_blackboard_plan().is_null()) {
set_blackboard_plan(Ref<BlackboardPlan>(memnew(BlackboardPlan)));
set_blackboard_plan(memnew(BlackboardPlan));
} else if (!RESOURCE_IS_BUILT_IN(get_blackboard_plan())) {
WARN_PRINT_ED("BTState: Using external resource for derived blackboard plan is not supported. Converted to built-in resource.");
set_blackboard_plan(get_blackboard_plan()->duplicate());
} else {
get_blackboard_plan()->set_base_plan(behavior_tree.is_valid() ? behavior_tree->get_blackboard_plan() : nullptr);
}
get_blackboard_plan()->set_base_plan(behavior_tree.is_valid() ? behavior_tree->get_blackboard_plan() : nullptr);
}
void BTState::_setup() {

View File

@ -67,7 +67,7 @@ protected:
public:
void set_blackboard_plan(const Ref<BlackboardPlan> &p_plan);
Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; }
_FORCE_INLINE_ Ref<BlackboardPlan> get_blackboard_plan() const { return blackboard_plan; }
Ref<Blackboard> get_blackboard() const { return blackboard; }

View File

@ -234,6 +234,7 @@ Variant VARIANT_DEFAULT(Variant::Type p_type);
#define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg")
#define IS_RESOURCE_FILE(m_path) (m_path.begins_with("res://") && m_path.find("::") == -1)
#define RESOURCE_TYPE_HINT(m_type) vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, m_type)
#define RESOURCE_IS_BUILT_IN(m_res) (m_res->get_path().is_empty() || m_res->get_path().contains("::"))
#ifdef TOOLS_ENABLED