Fix not registering BT instance with debugger when BTPlayer is removed and then added to SceneTree

This commit is contained in:
Serhii Snitsaruk 2023-09-09 13:37:09 +02:00
parent a625173786
commit 97eee2a801
3 changed files with 18 additions and 1 deletions

View File

@ -151,6 +151,11 @@ void BTPlayer::_notification(int p_notification) {
}
} break;
#ifdef DEBUG_ENABLED
case NOTIFICATION_ENTER_TREE: {
if (tree_instance.is_valid()) {
LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path());
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (tree_instance.is_valid()) {
LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path());

View File

@ -47,6 +47,11 @@ void BTState::_update(double p_delta) {
#ifdef DEBUG_ENABLED
void BTState::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
if (tree_instance.is_valid()) {
LimboDebugger::get_singleton()->register_bt_instance(tree_instance, get_path());
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (tree_instance.is_valid()) {
LimboDebugger::get_singleton()->unregister_bt_instance(tree_instance, get_path());

View File

@ -69,7 +69,12 @@ Error LimboDebugger::parse_message(void *p_user, const String &p_msg, const Arra
}
void LimboDebugger::register_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path) {
ERR_FAIL_COND(active_trees.has(p_player_path));
ERR_FAIL_COND(p_instance.is_null());
ERR_FAIL_COND(p_player_path.is_empty());
if (active_trees.has(p_player_path)) {
return;
}
print_line("DEBUG :: register :: ", p_player_path);
active_trees.insert(p_player_path, p_instance);
if (session_active) {
@ -78,7 +83,9 @@ void LimboDebugger::register_bt_instance(Ref<BTTask> p_instance, NodePath p_play
}
void LimboDebugger::unregister_bt_instance(Ref<BTTask> p_instance, NodePath p_player_path) {
ERR_FAIL_COND(p_instance.is_null());
ERR_FAIL_COND(p_player_path.is_empty());
print_line("DEBUG :: unregister :: ", p_player_path);
ERR_FAIL_COND(!active_trees.has(p_player_path));
if (tracked_tree == p_player_path) {