Skip to content

Add navigation path query parameter limits #102767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

smix8
Copy link
Contributor

@smix8 smix8 commented Feb 12, 2025

Adds navigation path query parameter limits.

Also implements proposal godotengine/godot-proposals#5978
Bugsquad edit: Closes godotengine/godot-proposals#5978

New path query properties

This adds new properties path_return_max_length and path_return_max_radius to NavigationAgent2D/3D and NavigationPathQueryParameters2D/3D.

The new properties can be used to clip the navigation path to a specific path length or radius from the start position ON navmesh. A common request for all kinds of more tactical games with a movement limit.

Also adds get_path_length() function that returns the length of the currently loaded path.

path_limits

Polygon search limit

This also adds path_search_max_polygons as a maxiumum polygon search cap.
This is set to a similar default as in some other engines that also have a node search cap of 4096.

If this polygon search cap is reached the pathfinding will reset the search and instead build a path from the start position to the polygon that was found the closest to the target position polygon so far.

This prevents path querys from running forever on badly optimized navigation maps with too many polygons. E.g. a target polygon can not be reached and the path search runs over all available polygons to confirm this, causing performance issues. As such this PR can be considered a performance boost for such projects, even if the actual cause of the problem lies elsewhere.

@JekSun97
Copy link
Contributor

JekSun97 commented Feb 12, 2025

Sounds very similar to my proposal - New pathfinding method for huge worlds

Copy link
Contributor

@kiroxas kiroxas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm not reading this correctly, but it seems like the path and radius limits are only here to clamp the result at the end. We could instead use this to limit iterations during the search path, because it seems like if we have a huge navmesh, this won't help on the performance side, as the whole map will be searched, and then we clamp. We should use it to limit the A* search.

@smix8
Copy link
Contributor Author

smix8 commented Feb 13, 2025

Maybe I'm not reading this correctly, but it seems like the path and radius limits are only here to clamp the result at the end. We could instead use this to limit iterations during the search path, because it seems like if we have a huge navmesh, this won't help on the performance side, as the whole map will be searched, and then we clamp. We should use it to limit the A* search.

It is mostly a postprocessing yes, not a performance optimization. We don't have a hierarchical structure yet that we could use so we would at least need to work with a very big margin to the search.

The problem what else ends up happening when you just stop the path search after the limit is that you will get nonsensical paths all the time with no direction stability should the path update. The paths will commonly go into the completely wrong direction as soon as any navmesh layout is even slighty more complex, and that is unwanted. E.g. Detour pathfinding with cap suffers greatly from this with the search and the only saving grace that it has is the tilemesh as the tilemesh hierarchical connections allows it to at least somehow head into a reasonable direction, and we dont have something similar yet.

@smix8 smix8 force-pushed the path_length_max branch 2 times, most recently from 07411d2 to 5a1aea5 Compare February 15, 2025 09:46
@smix8 smix8 force-pushed the path_length_max branch 4 times, most recently from 6db91bb to 7a0984d Compare March 18, 2025 11:40
@smix8 smix8 force-pushed the path_length_max branch 4 times, most recently from fcde7d0 to b3bd486 Compare April 2, 2025 15:27
@smix8 smix8 force-pushed the path_length_max branch from b3bd486 to 01e2a5e Compare May 6, 2025 13:48
@smix8 smix8 force-pushed the path_length_max branch from 01e2a5e to 9b15b94 Compare May 15, 2025 08:59
Copy link
Contributor

@MJacred MJacred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: No comment on the code itself.


Note: this PR makes the difference between "navigation finished" and "destination reached" more than ever clearer


Tested for 3D:

It's not a bug, but more of a limitation that would require further refinement to fix:
When so. uses max length or max radius, an agent can stop in the middle of a navigation link:

(Agent walking from right-to-left)
jump-link_max-length

Which is by no means wrong.

A problem will occur, though, if the path limit is smaller than your navigation link, because the system only looks at the navigation link start and end position: So it needs to go back to travel along the link.
The required refinement would need to find the nearest point on that line and start from there instead. (I managed to get an agent stuck on a navigation link with this edge case by decreasing the navigation length a bit more than what's depicted below.)

To make this case clearer, I didn't place the start and end position of the navigation link optimally:
(Agent walking from bottom-to-top)
jump-link_max-radius

@smix8
Copy link
Contributor Author

smix8 commented May 20, 2025

When so. uses max length or max radius, an agent can stop in the middle of a navigation link

Navigation links are all supposed to be script handled that facilitate the agent movement through a link. Outside of the most naive cases links do not function without a script as any map or path update would make it go back to the closest real navmesh polygon.

@smix8 smix8 force-pushed the path_length_max branch 3 times, most recently from 80696f1 to 77c715a Compare June 13, 2025 10:48
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Adds navigation path query parameter limits.
@smix8 smix8 force-pushed the path_length_max branch from 77c715a to cbd446a Compare June 13, 2025 12:42
@akien-mga akien-mga merged commit 436f8be into godotengine:master Jun 13, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@smix8 smix8 deleted the path_length_max branch June 14, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "maximum path query search length" property to NavigationAgent
6 participants