From dc40109ade366ee8b446ee189a1335591de45426 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 23 Jan 2024 15:56:30 +0100 Subject: [PATCH] Fix default object value issues --- bt/behavior_tree.cpp | 11 +++++++++-- bt/behavior_tree.h | 5 +---- bt/bt_player.cpp | 6 +----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bt/behavior_tree.cpp b/bt/behavior_tree.cpp index 5508b6d..f06b315 100644 --- a/bt/behavior_tree.cpp +++ b/bt/behavior_tree.cpp @@ -22,6 +22,14 @@ #include "godot_cpp/core/error_macros.hpp" #endif // ! LIMBOAI_GDEXTENSION +void BehaviorTree::set_blackboard_source(const Ref &p_source) { + blackboard_source = p_source; + if (blackboard_source.is_null()) { + blackboard_source = Ref(memnew(BlackboardSource)); + } + emit_changed(); +} + Ref BehaviorTree::clone() const { Ref copy = duplicate(false); copy->set_path(""); @@ -57,9 +65,8 @@ void BehaviorTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "description", PROPERTY_HINT_MULTILINE_TEXT), "set_description", "get_description"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root_task", PROPERTY_HINT_RESOURCE_TYPE, "BTTask", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_root_task", "get_root_task"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard_source", PROPERTY_HINT_RESOURCE_TYPE, "BlackboardSource", PROPERTY_USAGE_DEFAULT), "set_blackboard_source", "get_blackboard_source"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard_source", PROPERTY_HINT_RESOURCE_TYPE, "BlackboardSource", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT), "set_blackboard_source", "get_blackboard_source"); } BehaviorTree::BehaviorTree() { - blackboard_source = Ref(memnew(BlackboardSource)); } diff --git a/bt/behavior_tree.h b/bt/behavior_tree.h index 3687524..6b5305f 100644 --- a/bt/behavior_tree.h +++ b/bt/behavior_tree.h @@ -40,10 +40,7 @@ public: virtual bool editor_can_reload_from_file() override { return false; } #endif - void set_blackboard_source(const Ref &p_source) { - blackboard_source = p_source; - emit_changed(); - } + void set_blackboard_source(const Ref &p_source); Ref get_blackboard_source() const { return blackboard_source; } void set_description(String p_value) { diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 9358791..3687916 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -86,9 +86,6 @@ void BTPlayer::set_behavior_tree(const Ref &p_tree) { void BTPlayer::set_blackboard_source(const Ref &p_source) { blackboard_source = p_source; - if (blackboard_source.is_null()) { - blackboard_source = Ref(memnew(BlackboardSource)); - } _update_blackboard_source(); } @@ -232,7 +229,7 @@ void BTPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode", PROPERTY_HINT_ENUM, "Idle,Physics,Manual"), "set_update_mode", "get_update_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "get_active"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard", PROPERTY_HINT_NONE, "Blackboard", 0), "set_blackboard", "get_blackboard"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard_source", PROPERTY_HINT_RESOURCE_TYPE, "BlackboardSource", PROPERTY_USAGE_DEFAULT), "set_blackboard_source", "get_blackboard_source"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "blackboard_source", PROPERTY_HINT_RESOURCE_TYPE, "BlackboardSource", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT), "set_blackboard_source", "get_blackboard_source"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "prefetch_nodepath_vars"), "set_prefetch_nodepath_vars", "get_prefetch_nodepath_vars"); BIND_ENUM_CONSTANT(IDLE); @@ -250,7 +247,6 @@ void BTPlayer::_bind_methods() { } BTPlayer::BTPlayer() { - blackboard = Ref(memnew(Blackboard)); } BTPlayer::~BTPlayer() {