Fix agent avoidance position not updated when entering SceneTree

Fixes agent avoidance position not updated when entering SceneTree.
This commit is contained in:
smix8 2023-05-15 21:54:00 +02:00
parent 2ac4e3bb30
commit 5296b91592
4 changed files with 14 additions and 0 deletions

View File

@ -151,6 +151,10 @@ void NavigationAgent2D::_notification(int p_what) {
set_agent_parent(get_parent());
set_physics_process_internal(true);
if (agent_parent && avoidance_enabled) {
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
}
#ifdef DEBUG_ENABLED
if (NavigationServer2D::get_singleton()->get_debug_enabled()) {
debug_path_dirty = true;

View File

@ -63,6 +63,9 @@ void NavigationObstacle2D::_notification(int p_what) {
case NOTIFICATION_POST_ENTER_TREE: {
set_agent_parent(get_parent());
set_physics_process_internal(true);
if (parent_node2d && parent_node2d->is_inside_tree()) {
NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position());
}
} break;
case NOTIFICATION_EXIT_TREE: {

View File

@ -154,6 +154,10 @@ void NavigationAgent3D::_notification(int p_what) {
set_agent_parent(get_parent());
set_physics_process_internal(true);
if (agent_parent && avoidance_enabled) {
NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
}
#ifdef DEBUG_ENABLED
if (NavigationServer3D::get_singleton()->get_debug_enabled()) {
debug_path_dirty = true;

View File

@ -62,6 +62,9 @@ void NavigationObstacle3D::_notification(int p_what) {
case NOTIFICATION_POST_ENTER_TREE: {
set_agent_parent(get_parent());
set_physics_process_internal(true);
if (parent_node3d && parent_node3d->is_inside_tree()) {
NavigationServer3D::get_singleton()->agent_set_position(agent, parent_node3d->get_global_position());
}
} break;
case NOTIFICATION_EXIT_TREE: {