diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index bf966db892f..62afe0d89b5 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -168,7 +168,7 @@ void NavigationAgent2D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (agent_parent) { + if (agent_parent && target_position_submitted) { if (avoidance_enabled) { // agent_position on NavigationServer is avoidance only and has nothing to do with pathfinding // no point in flooding NavigationServer queue with agent position updates that get send to the void if avoidance is not used @@ -329,6 +329,7 @@ real_t NavigationAgent2D::get_path_max_distance() { void NavigationAgent2D::set_target_location(Vector2 p_location) { target_location = p_location; + target_position_submitted = true; _request_repath(); } @@ -413,6 +414,9 @@ void NavigationAgent2D::update_navigation() { if (!agent_parent->is_inside_tree()) { return; } + if (!target_position_submitted) { + return; + } if (update_frame_id == Engine::get_singleton()->get_physics_frames()) { return; } @@ -519,6 +523,7 @@ void NavigationAgent2D::update_navigation() { _check_distance_to_target(); navigation_path_index -= 1; navigation_finished = true; + target_position_submitted = false; emit_signal(SNAME("navigation_finished")); break; } diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h index 747c1570f85..439192cce72 100644 --- a/scene/2d/navigation_agent_2d.h +++ b/scene/2d/navigation_agent_2d.h @@ -61,6 +61,7 @@ class NavigationAgent2D : public Node { real_t path_max_distance = 3.0; Vector2 target_location; + bool target_position_submitted = false; Ref navigation_query; Ref navigation_result; int navigation_path_index = 0; diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp index 26dd8dfba94..741f7397adb 100644 --- a/scene/3d/navigation_agent_3d.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -174,7 +174,7 @@ void NavigationAgent3D::_notification(int p_what) { } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (agent_parent) { + if (agent_parent && target_position_submitted) { if (avoidance_enabled) { // agent_position on NavigationServer is avoidance only and has nothing to do with pathfinding // no point in flooding NavigationServer queue with agent position updates that get send to the void if avoidance is not used @@ -345,6 +345,7 @@ real_t NavigationAgent3D::get_path_max_distance() { void NavigationAgent3D::set_target_location(Vector3 p_location) { target_location = p_location; + target_position_submitted = true; _request_repath(); } @@ -428,6 +429,9 @@ void NavigationAgent3D::update_navigation() { if (!agent_parent->is_inside_tree()) { return; } + if (!target_position_submitted) { + return; + } if (update_frame_id == Engine::get_singleton()->get_physics_frames()) { return; } @@ -536,6 +540,7 @@ void NavigationAgent3D::update_navigation() { _check_distance_to_target(); navigation_path_index -= 1; navigation_finished = true; + target_position_submitted = false; emit_signal(SNAME("navigation_finished")); break; } diff --git a/scene/3d/navigation_agent_3d.h b/scene/3d/navigation_agent_3d.h index b950367a87e..cda218b538f 100644 --- a/scene/3d/navigation_agent_3d.h +++ b/scene/3d/navigation_agent_3d.h @@ -63,6 +63,7 @@ class NavigationAgent3D : public Node { real_t path_max_distance = 3.0; Vector3 target_location; + bool target_position_submitted = false; Ref navigation_query; Ref navigation_result; int navigation_path_index = 0;