I couldn’t find my answer in the documentation but hoping that someone might be able to help me here. Is there a way to get all the nodes that are inside a given NavigationPolygon that is attached to a NavigationRegion2D?
I’m trying to set up patrol points for my AI, but since there can be multiple navigation regions, I want each region to have their own points.
I know I can manually add them, but it would be a lot easier and cleaner if, during runtime, I could just get a list of all the patrol points for any given region.
No there is no build-in way for this. The navigation system does not keep record of any generic SceneTree objects like Nodes.
You would need to reconstruct the polygons from the navmesh data and check them with e.g. Geometry2D.is_point_in_polygon() if the point is inside the polygons.
To do this for a NavigationPolygon resources you get the vertices array and then loop over all the get_polygon_count() polygons, get the polygon indices with get_polygon() and recreate the polygon array for the Geometry2D function. If the NavigationRegion2D is also transformed you need to apply the global transform to the vertices as well.