diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 6308112..473c366 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -88,7 +88,7 @@ void BlackboardPlan::_get_property_list(List *p_list) const { BBVariable var = p.second; // * Editor - if (!is_derived() || !var_name.begins_with("_")) { + if (var.get_type() != Variant::NIL && (!is_derived() || !var_name.begins_with("_"))) { p_list->push_back(PropertyInfo(var.get_type(), var_name, var.get_hint(), var.get_hint_string(), PROPERTY_USAGE_EDITOR)); } diff --git a/bt/bt_player.cpp b/bt/bt_player.cpp index 2cbdf8d..df22d40 100644 --- a/bt/bt_player.cpp +++ b/bt/bt_player.cpp @@ -193,6 +193,8 @@ void BTPlayer::_notification(int p_notification) { #ifdef DEBUG_ENABLED _set_monitor_performance(monitor_performance); #endif + } else { + _update_blackboard_plan(); } } break; case NOTIFICATION_ENTER_TREE: { diff --git a/bt/bt_state.h b/bt/bt_state.h index 3ac823b..717b975 100644 --- a/bt/bt_state.h +++ b/bt/bt_state.h @@ -26,14 +26,13 @@ private: StringName success_event; StringName failure_event; - void _update_blackboard_plan(); - protected: static void _bind_methods(); void _notification(int p_notification); virtual bool _should_use_new_scope() const override { return true; } + virtual void _update_blackboard_plan() override; virtual void _setup() override; virtual void _exit() override; diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index f1a5e0c..f11001f 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -215,7 +215,9 @@ void LimboAIEditor::_load_bt(String p_path) { ERR_FAIL_COND_MSG(p_path.is_empty(), "Empty p_path"); Ref bt = RESOURCE_LOAD(p_path, "BehaviorTree"); ERR_FAIL_COND(!bt.is_valid()); - + if (bt->get_blackboard_plan().is_null()) { + bt->set_blackboard_plan(memnew(BlackboardPlan)); + } if (history.find(bt) != -1) { history.erase(bt); history.push_back(bt); diff --git a/hsm/limbo_state.cpp b/hsm/limbo_state.cpp index 5931d25..4fa3df8 100644 --- a/hsm/limbo_state.cpp +++ b/hsm/limbo_state.cpp @@ -26,6 +26,14 @@ #ifdef LIMBOAI_GDEXTENSION #endif +void LimboState::set_blackboard_plan(const Ref &p_plan) { + blackboard_plan = p_plan; + _update_blackboard_plan(); +} + +void LimboState::_update_blackboard_plan() { +} + LimboState *LimboState::get_root() const { const LimboState *state = this; while (state->get_parent() && IS_CLASS(state->get_parent(), LimboState)) { @@ -159,6 +167,11 @@ void LimboState::clear_guard() { void LimboState::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_READY: { + if (Engine::get_singleton()->is_editor_hint()) { + _update_blackboard_plan(); + } + } break; case NOTIFICATION_EXIT_TREE: { if (active) { _exit(); diff --git a/hsm/limbo_state.h b/hsm/limbo_state.h index 571861e..79f68ec 100644 --- a/hsm/limbo_state.h +++ b/hsm/limbo_state.h @@ -58,6 +58,7 @@ protected: virtual bool _dispatch(const StringName &p_event, const Variant &p_cargo = Variant()); virtual bool _should_use_new_scope() const { return blackboard_plan.is_valid() || is_root(); } + virtual void _update_blackboard_plan(); virtual void _setup(); virtual void _enter(); @@ -72,7 +73,7 @@ protected: #endif // LIMBOAI_MODULE public: - void set_blackboard_plan(const Ref &p_plan) { blackboard_plan = p_plan; } + void set_blackboard_plan(const Ref &p_plan); Ref get_blackboard_plan() const { return blackboard_plan; } Ref get_blackboard() const { return blackboard; }