public sealed class NavMeshQueryAsks a NavMesh questions: which polygon is under a point, how to get from one to another, and what a straight line runs into on the way.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
One per thread, reused. Everything a search needs — the node pool, the open list, the visited set — lives here and is cleared rather than reallocated, so a query costs no allocation after the first. That is the whole reason this is an object and not a static class over the mesh: sharing one between two threads is a data race, and making the state local to a call would allocate it every frame.
The mesh may change under it. Nothing here caches a tile or a polygon between calls, and every reference is resolved through the salt, so a tile unloaded between two queries makes the second one fail rather than read freed data.
Fields and properties (3)
public NavMesh MeshThe mesh being queried.
public int LastSearchNodesHow many polygons the last search expanded. Diagnostic.
public int LastStraightPathStepsHow many corridor steps the last string-pull walked, restarts included. Diagnostic.
Methods (12)
public NavMeshQuery(NavMesh mesh)Creates a query over a mesh.
public bool FindNearestPoly(Vector3 center, Vector3 halfExtents, NavQueryFilter filter, out NavPolyRef poly, out Vector3 point)Finds the polygon nearest a point.
public bool ClosestPointOnPoly(NavPolyRef reference, Vector3 position, out Vector3 closest, out bool isOverPoly)The point of a polygon closest to a position.
public bool GetPolyHeight(NavPolyRef reference, Vector3 position, out float height)The height of the surface at a point on a polygon.
public NavPathStatus FindPath(NavPolyRef start, NavPolyRef end, Vector3 startPosition, Vector3 endPosition, NavQueryFilter filter, Span<NavPolyRef> path, out int count)Finds a path from one polygon to another.
public NavPathStatus InitSlicedFindPath(NavPolyRef start, NavPolyRef end, Vector3 startPosition, Vector3 endPosition, NavQueryFilter filter)Starts a search that can be run a little at a time.
public NavPathStatus UpdateSlicedFindPath(int maximumIterations, out int performed)Runs a started search for a while.
public NavPathStatus FinalizeSlicedFindPath(Span<NavPolyRef> path, out int count)Reads back the path a finished search found.
public int FindStraightPath(Vector3 startPosition, Vector3 endPosition, ReadOnlySpan<NavPolyRef> path, Span<NavPathPoint> points)Pulls a corridor of polygons straight, into the corners an agent turns at.
public bool Raycast(NavPolyRef start, Vector3 startPosition, Vector3 endPosition, NavQueryFilter filter, out NavRaycastHit hit)Walks a straight line across the surface until it leaves it.
public bool Raycast(NavPolyRef start, Vector3 startPosition, Vector3 endPosition, NavQueryFilter filter, out NavRaycastHit hit, Span<NavPolyRef> visited, out int visitedCount)Walks a straight line across the surface, recording the polygons it crossed.
public bool MoveAlongSurface(NavPolyRef start, Vector3 startPosition, Vector3 endPosition, NavQueryFilter filter, out Vector3 position, out NavPolyRef poly)Moves a point across the surface, sliding along whatever it runs into.
Used by (25)
- CrowdBenchmarksVixen.Benchmarks.Navigation
- PathQueueBenchmarksVixen.Benchmarks.Navigation
- QueryBenchmarksVixen.Benchmarks.Navigation
- CrossTileConnectionTestsVixen.Navigation.Tests
- CrowdVixen.Navigation
- CrowdRetargetTestsVixen.Navigation.Tests
- CrowdTestsVixen.Navigation.Tests
- DetailMeshTestsVixen.Navigation.Tests
- HeightfieldTestsVixen.Navigation.Tests
- NavAreaVolumeTestsVixen.Navigation.Tests
- NavMeshAssetTestsVixen.Navigation.Tests
- NavMeshBakeTestsVixen.Navigation.Tests
- NavMeshDebugDrawTestsVixen.Navigation.Tests
- NavMeshQueryTestsVixen.Navigation.Tests
- NavPathQueueVixen.Navigation
- NavPathQueueJobTestsVixen.Navigation.Tests
- NavPathQueueTestsVixen.Navigation.Tests
- NavTileCacheTestsVixen.Navigation.Tests
- NavigationAllocationTestsVixen.Navigation.Tests
- OffMeshConnectionTestsVixen.Navigation.Tests
- PathCorridorVixen.Navigation
- RegionMergeTestsVixen.Navigation.Tests
- SliceJobVixen.Navigation
- WatershedTestsVixen.Navigation.Tests
- NavMeshImporterTestsVixen.Editor.Assets.Tests