From 5296b9159215405416b420896c07bdd86787a11f Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Mon, 15 May 2023 21:54:00 +0200 Subject: [PATCH] Fix agent avoidance position not updated when entering SceneTree Fixes agent avoidance position not updated when entering SceneTree. --- scene/2d/navigation_agent_2d.cpp | 4 ++++ scene/2d/navigation_obstacle_2d.cpp | 3 +++ scene/3d/navigation_agent_3d.cpp | 4 ++++ scene/3d/navigation_obstacle_3d.cpp | 3 +++ 4 files changed, 14 insertions(+) diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index d101cac4ebd..8dca7b52970 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -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; diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index 2366cb696ef..a23de5646ac 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -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: { diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp index 7d404ffa075..bd574257777 100644 --- a/scene/3d/navigation_agent_3d.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -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; diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp index 14d93fb0e03..66d14538d7a 100644 --- a/scene/3d/navigation_obstacle_3d.cpp +++ b/scene/3d/navigation_obstacle_3d.cpp @@ -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: {