Compare commits

..

1 Commits

Author SHA1 Message Date
Legendsmith a22185e784
Merge bbdafa9033 into 0584b0401f 2025-01-21 21:13:57 +09:00
3 changed files with 14 additions and 26 deletions

View File

@ -83,7 +83,7 @@ void BTInstance::register_with_debugger() {
void BTInstance::unregister_with_debugger() { void BTInstance::unregister_with_debugger() {
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (LimboDebugger::get_singleton() && LimboDebugger::get_singleton()->is_active()) { if (LimboDebugger::get_singleton()->is_active()) {
LimboDebugger::get_singleton()->unregister_bt_instance(get_instance_id()); LimboDebugger::get_singleton()->unregister_bt_instance(get_instance_id());
} }
#endif #endif
@ -151,6 +151,5 @@ BTInstance::~BTInstance() {
emit_signal(LW_NAME(freed)); emit_signal(LW_NAME(freed));
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
_remove_custom_monitor(); _remove_custom_monitor();
unregister_with_debugger();
#endif #endif
} }

View File

@ -42,7 +42,7 @@
VARIANT_ENUM_CAST(BTPlayer::UpdateMode); VARIANT_ENUM_CAST(BTPlayer::UpdateMode);
void BTPlayer::_instantiate_bt() { void BTPlayer::_load_tree() {
bt_instance.unref(); bt_instance.unref();
ERR_FAIL_COND_MSG(!behavior_tree.is_valid(), "BTPlayer: Initialization failed - needs a valid behavior tree."); ERR_FAIL_COND_MSG(!behavior_tree.is_valid(), "BTPlayer: Initialization failed - needs a valid behavior tree.");
ERR_FAIL_COND_MSG(!behavior_tree->get_root_task().is_valid(), "BTPlayer: Initialization failed - behavior tree has no valid root task."); ERR_FAIL_COND_MSG(!behavior_tree->get_root_task().is_valid(), "BTPlayer: Initialization failed - behavior tree has no valid root task.");
@ -70,19 +70,6 @@ void BTPlayer::_update_blackboard_plan() {
blackboard_plan->set_base_plan(behavior_tree.is_valid() ? behavior_tree->get_blackboard_plan() : nullptr); blackboard_plan->set_base_plan(behavior_tree.is_valid() ? behavior_tree->get_blackboard_plan() : nullptr);
} }
void BTPlayer::_initialize() {
if (blackboard.is_null()) {
blackboard = Ref<Blackboard>(memnew(Blackboard));
}
if (blackboard_plan.is_valid()) {
// Don't overwrite existing blackboard values as they may be initialized from code.
blackboard_plan->populate_blackboard(blackboard, false, this, _get_scene_root());
}
if (behavior_tree.is_valid()) {
_instantiate_bt();
}
}
void BTPlayer::set_bt_instance(const Ref<BTInstance> &p_bt_instance) { void BTPlayer::set_bt_instance(const Ref<BTInstance> &p_bt_instance) {
ERR_FAIL_COND_MSG(p_bt_instance.is_null(), "BTPlayer: Failed to set behavior tree instance - instance is null."); ERR_FAIL_COND_MSG(p_bt_instance.is_null(), "BTPlayer: Failed to set behavior tree instance - instance is null.");
ERR_FAIL_COND_MSG(!p_bt_instance->is_instance_valid(), "BTPlayer: Failed to set behavior tree instance - instance is not valid."); ERR_FAIL_COND_MSG(!p_bt_instance->is_instance_valid(), "BTPlayer: Failed to set behavior tree instance - instance is not valid.");
@ -91,11 +78,6 @@ void BTPlayer::set_bt_instance(const Ref<BTInstance> &p_bt_instance) {
blackboard = p_bt_instance->get_blackboard(); blackboard = p_bt_instance->get_blackboard();
agent_node = p_bt_instance->get_agent()->get_path(); agent_node = p_bt_instance->get_agent()->get_path();
#ifdef DEBUG_ENABLED
bt_instance->set_monitor_performance(monitor_performance);
bt_instance->register_with_debugger();
#endif // DEBUG_ENABLED
blackboard_plan.unref(); blackboard_plan.unref();
behavior_tree.unref(); behavior_tree.unref();
} }
@ -122,8 +104,7 @@ void BTPlayer::set_behavior_tree(const Ref<BehaviorTree> &p_tree) {
} else { } else {
behavior_tree = p_tree; behavior_tree = p_tree;
if (get_owner() && is_inside_tree()) { if (get_owner() && is_inside_tree()) {
_update_blackboard_plan(); _load_tree();
_initialize();
} }
} }
} }
@ -198,7 +179,16 @@ void BTPlayer::_notification(int p_notification) {
} break; } break;
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint()) { if (!Engine::get_singleton()->is_editor_hint()) {
_initialize(); if (blackboard.is_null()) {
blackboard = Ref<Blackboard>(memnew(Blackboard));
}
if (blackboard_plan.is_valid()) {
// Don't overwrite existing blackboard values as they may be initialized from code.
blackboard_plan->populate_blackboard(blackboard, false, this, _get_scene_root());
}
if (behavior_tree.is_valid()) {
_load_tree();
}
} else { } else {
_update_blackboard_plan(); _update_blackboard_plan();
} }

View File

@ -48,9 +48,8 @@ private:
Ref<BTInstance> bt_instance; Ref<BTInstance> bt_instance;
void _instantiate_bt(); void _load_tree();
void _update_blackboard_plan(); void _update_blackboard_plan();
void _initialize();
_FORCE_INLINE_ Node *_get_scene_root() const { return scene_root_hint ? scene_root_hint : get_owner(); } _FORCE_INLINE_ Node *_get_scene_root() const { return scene_root_hint ? scene_root_hint : get_owner(); }
protected: protected: