Struct NavMeshGraph
Navigation Mesh implementation with support for raycasting, area cost, flags and arbitrarily curved surfaces.
v1.1 adds features to populate the graph from within jobs. See Populate(NativeArray<Vector3>, NativeArray<int>) as well as some variations on this, including one that copies the contents from another NavMehsGraph, which can be efficient if you need to make slight adjustments to the graph as fast as possible.
SetUnwalkable(int), which can be used to essentialy cut some areas from the NavMesh. Depending on your use case, this may be a very efficient way to dynamically alter the graph without a lot of overhead. Using GetOverlappingTriangles(AABB, NativeList<int>), an area can be scanned and then these triangles can be excluded from pathfinding queries.
Paths can be processed using: NavMeshGraphCorners - creates a nice corner array from a starting position to the goal for flat worlds with slopes NavMeshGraphCorners3D - creates a nice corner array for arbitrarily curved worlds NavMeshGraphUnroller - processes the path so that it can be used for realtime steering behaviour
Namespace: AnyPath.Graphs.NavMesh
Assembly: AnyPath.dll
Syntax
public struct NavMeshGraph : IGraph<NavMeshGraphLocation>, IDisposable
Remarks
Since v1.1, all of the constructors make an internal copy of the supplied arrays. Also, any triangle that has a cost of infinity is considered unwalkable and will never be part of a path
Constructors
NavMeshGraph(List<Vector3>, List<int>, Matrix4x4, Allocator, List<EnterCostAndFlags>, int, int)
Construct a NavMesh from a set of vertices and triangles. The NavMesh is populated automatically.
Declaration
public NavMeshGraph(List<Vector3> vertices, List<int> triangles, Matrix4x4 localToWorldMatrix, Allocator allocator, List<NavMeshGraph.EnterCostAndFlags> enterCostAndFlags = null, int trianglesPerOctant = 16, int maxOctreeDepth = 5)
Parameters
| Type | Name | Description |
|---|---|---|
| List<Vector3> | vertices | Vertices to use. Similar to how a Unity mesh is constructed. |
| List<int> | triangles | Array describing the triangles using the indices in the vertex array. Length must be a multiple of 3 as each set of 3 indices describres a triangle |
| Matrix4x4 | localToWorldMatrix | The local to world matrix to use. This is useful if you want the navmesh to use world space coordinates. Use Matrix4x4.identity if the vertices are already in world space or if you want to keep the coordinates in the local space of the mesh. |
| Allocator | allocator | Allocator to use |
| List<NavMeshGraph.EnterCostAndFlags> | enterCostAndFlags | Array with cost and flags per triangle. Note that one triangle equals 3 indices in the triangles array. So index zero in this array corresponds to the first set of 3 in the triangles array. Length should be the amount of triangles. (triangles parameter's length divided by 3). Null is allowed for this parameter, and will assign no extra cost and flags to the triangles. |
| int | trianglesPerOctant | Max triangles per octant for the internal octree. Depending on |
| int | maxOctreeDepth | Max depth of the internal octree for raycast and closest location accellerating. If your mesh is very large, it may be beneficial to increase this value. Finding a good balance is key to having optimal raycast and closest location performance. |
Remarks
Note that the vertices may need to be welded together first, depending on your source of data.
Not super efficient, it's advised to use another constructor overload
NavMeshGraph(Allocator, int, int, int, int)
Constructs an empty nav mesh graph, to be populated later with any of the Populate(NativeArray<Vector3>, NativeArray<int>) methods.
Declaration
public NavMeshGraph(Allocator allocator, int trianglesPerOctant = 16, int maxOctreeDepth = 5, int initialVertexCapacity = 0, int initialIndicesCapacity = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Allocator | allocator | Allocator to use. Make sure to use the same allocator as the supplied arrays. |
| int | trianglesPerOctant | Max triangles per octant for the internal octree |
| int | maxOctreeDepth | Max depth of the internal octree for raycast accellerating |
| int | initialVertexCapacity | Pre allocate memory for the vertices, if you know how large your mesh is going to be, this helps with performance when populating |
| int | initialIndicesCapacity | Pre allocate memory for the triangle indices, if you know how large your mesh is going to be, this helps with performance when populating |
NavMeshGraph(NativeArray<Vector3>, NativeArray<int>, NativeArray<EnterCostAndFlags>, Matrix4x4, Allocator, int, int)
Construct a NavMesh from a set of vertices and triangles. The NavMesh is populated automatically.
Declaration
public NavMeshGraph(NativeArray<Vector3> vertices, NativeArray<int> triangles, NativeArray<NavMeshGraph.EnterCostAndFlags> enterCostAndFlags, Matrix4x4 localToWorldMatrix, Allocator allocator, int trianglesPerOctant = 16, int maxOctreeDepth = 5)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<Vector3> | vertices | Vertices to use. Similar to how a Unity mesh is constructed. |
| NativeArray<int> | triangles | Triangle indices to use. Similar to how a Unity mesh is constructed. |
| NativeArray<NavMeshGraph.EnterCostAndFlags> | enterCostAndFlags | Array with cost and flags per triangle. Length should be the amount of triangles. (triangles array divided by 3). |
| Matrix4x4 | localToWorldMatrix | The local to world matrix to use. This is useful if you want the navmesh to use world space coordinates. Use Matrix4x4.identity if the vertices are already in world space or if you want to keep the coordinates in the local space of the mesh. |
| Allocator | allocator | Allocator to use. Make sure to use the same allocator as the supplied arrays. |
| int | trianglesPerOctant | Max triangles per octant for the internal octree |
| int | maxOctreeDepth | Max depth of the internal octree for raycast and closest location accellerating. If your mesh is very large, it may be beneficial to increase this value. Finding a good balance is key to having optimal raycast and closest location performance. |
Remarks
Breaking change: the supplied arrays are copied as of v1.1. Dispose of the native arrays separately.
NavMeshGraph(Vector3[], int[], Matrix4x4, Allocator, EnterCostAndFlags[], int, int)
Construct a NavMesh from a set of vertices and triangles. The NavMesh is populated automatically.
Declaration
public NavMeshGraph(Vector3[] vertices, int[] triangles, Matrix4x4 localToWorldMatrix, Allocator allocator, NavMeshGraph.EnterCostAndFlags[] enterCostAndFlags = null, int trianglesPerOctant = 16, int maxOctreeDepth = 5)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | vertices | Vertices to use. Similar to how a Unity mesh is constructed. |
| int[] | triangles | Triangle indices to use. Similar to how a Unity mesh is constructed. |
| Matrix4x4 | localToWorldMatrix | The local to world matrix to use. Use Matrix4x4.identity if the vertices are already in world space or if you want to keep the coordinates in the local mesh space. |
| Allocator | allocator | Allocator to use |
| EnterCostAndFlags[] | enterCostAndFlags | Array with cost and flags per triangle. Length should be the amount of triangles. (triangles array divided by 3). Null is allowed for this parameter, and will assign no extra cost and flags to the triangles. |
| int | trianglesPerOctant | Max triangles per octant for the internal octree |
| int | maxOctreeDepth | Max depth of the internal octree for raycast and closest location accellerating. If your mesh is very large, it may be beneficial to increase this value. Finding a good balance is key to having optimal raycast and closest location performance. |
Remarks
An internal copy is made of the supplied arrays
Properties
CostAndFlags
Read only access to the enter cost and flags of the mesh
Declaration
public NativeArray<NavMeshGraph.EnterCostAndFlags>.ReadOnly CostAndFlags { get; }
Property Value
| Type | Description |
|---|---|
| NativeArray<NavMeshGraph.EnterCostAndFlags>.ReadOnly |
Octree
Access to the internal octree of the graph for advanced location queries.
Declaration
public NativeOctree<int> Octree { get; }
Property Value
| Type | Description |
|---|---|
| NativeOctree<int> |
Remarks
Warning: do not modify the octree as this will corrupt the state of the graph.
TriangleCount
Amount of triangles contained in the mesh
Declaration
public int TriangleCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Triangles
Read only access to the triangle indices of the mesh. Each triangle has three consecutive ints pointing to the index in the Vertices array
Declaration
public NativeArray<int>.ReadOnly Triangles { get; }
Property Value
| Type | Description |
|---|---|
| NativeArray<int>.ReadOnly |
Vertices
Read only access to the vertices of the mesh
Declaration
public NativeArray<Vector3>.ReadOnly Vertices { get; }
Property Value
| Type | Description |
|---|---|
| NativeArray<Vector3>.ReadOnly |
Methods
ClosestLocation(NearestNeighbourCache, float3, float, ClosestNavMeshLocationPredicate, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point, with a custom 'filter' predicate. This predicate can be used for instance to check if there is a clear line of sight between the position and the location that is returned.
Declaration
public bool ClosestLocation(NativeOctree<int>.NearestNeighbourCache cache, float3 position, float maxDistance, ClosestNavMeshLocationPredicate predicate, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeOctree<int>.NearestNeighbourCache | cache | Re-usable cache for the algorithm. If you need to perform a lot of closest location queries in a row, it is faster to allocate this cache once and re-use it for every query. |
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius. Locations beyond this distance will not be visited. Keeping this value within reasonable limits may dramatically increase performance. |
| ClosestNavMeshLocationPredicate | predicate | A custom function to determine wether a location is valid as a closest location. If false is returned, the next closest location after that is attempted, and so on. |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
Remarks
This function cannot be used in a burst compiled job context. Use the overload that accepts a Unity.Burst.FunctionPointer<T> instead.
ClosestLocation(NearestNeighbourCache, float3, float, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point.
Declaration
public bool ClosestLocation(NativeOctree<int>.NearestNeighbourCache cache, float3 position, float maxDistance, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeOctree<int>.NearestNeighbourCache | cache | Re-usable cache for the algorithm. If you need to perform a lot of closest location queries in a row, it is faster to allocate this cache once and re-use it for every query. |
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
ClosestLocation(NearestNeighbourCache, float3, float, int, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point.
Declaration
public bool ClosestLocation(NativeOctree<int>.NearestNeighbourCache cache, float3 position, float maxDistance, int flagBitMask, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeOctree<int>.NearestNeighbourCache | cache | Re-usable cache for the algorithm. If you need to perform a lot of closest location queries in a row, it is faster to allocate this cache once and re-use it for every query. |
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius |
| int | flagBitMask | A bitwise AND is performed on the triangle candidates and if any bit is true, the triangle is considered. |
| NavMeshGraphLocation | location | Returns the closest location on the graph |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
ClosestLocation(NearestNeighbourCache, float3, float, FunctionPointer<ClosestNavMeshLocationPredicate>, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point, with a custom 'filter' predicate. This predicate can be used for instance to check if there is a clear line of sight between the position and the location that is returned.
Declaration
public bool ClosestLocation(NativeOctree<int>.NearestNeighbourCache cache, float3 position, float maxDistance, FunctionPointer<ClosestNavMeshLocationPredicate> predicate, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeOctree<int>.NearestNeighbourCache | cache | Re-usable cache for the algorithm. If you need to perform a lot of closest location queries in a row, it is faster to allocate this cache once and re-use it for every query. |
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius. Locations beyond this distance will not be visited. Keeping this value within reasonable limits may dramatically increase performance. |
| FunctionPointer<ClosestNavMeshLocationPredicate> | predicate | A custom function to determine wether a location is valid as a closest location. If false is returned, the next closest location after that is attempted, and so on. |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
ClosestLocation(float3, float, ClosestNavMeshLocationPredicate, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point, with a custom 'filter' predicate. This predicate can be used for instance to check if there is a clear line of sight between the position and the location that is returned.
Declaration
public bool ClosestLocation(float3 position, float maxDistance, ClosestNavMeshLocationPredicate predicate, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius. Locations beyond this distance will not be visited. Keeping this value within reasonable limits may dramatically increase performance. |
| ClosestNavMeshLocationPredicate | predicate | A custom function to determine wether a location is valid as a closest location. If false is returned, the next closest location after that is attempted, and so on. |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
Remarks
This function cannot be used in a burst compiled job context. Use the overload that accepts a Unity.Burst.FunctionPointer<T> instead.
ClosestLocation(float3, float, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point.
Declaration
public bool ClosestLocation(float3 position, float maxDistance, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
ClosestLocation(float3, float, int, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point.
Declaration
public bool ClosestLocation(float3 position, float maxDistance, int flagBitMask, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius |
| int | flagBitMask | A bitwise AND is performed on the triangle candidates and if any bit is true, the triangle is considered. |
| NavMeshGraphLocation | location | Returns the closest location on the graph |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
ClosestLocation(float3, float, FunctionPointer<ClosestNavMeshLocationPredicate>, out NavMeshGraphLocation)
Returns the closest location on the navmesh from a point, with a custom 'filter' predicate. This predicate can be used for instance to check if there is a clear line of sight between the position and the location that is returned.
Declaration
public bool ClosestLocation(float3 position, float maxDistance, FunctionPointer<ClosestNavMeshLocationPredicate> predicate, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| float3 | position | The center position to search from |
| float | maxDistance | The max search radius. Locations beyond this distance will not be visited. Keeping this value within reasonable limits may dramatically increase performance. |
| FunctionPointer<ClosestNavMeshLocationPredicate> | predicate | A custom function to determine wether a location is valid as a closest location. If false is returned, the next closest location after that is attempted, and so on. |
| NavMeshGraphLocation | location | Returns the closest location on the navmesh |
Returns
| Type | Description |
|---|---|
| bool | Wether a location was found within the given radius |
Collect(NavMeshGraphLocation, ref NativeList<Edge<NavMeshGraphLocation>>)
Implement adding all the directed edges that go from the input node.
Declaration
public void Collect(NavMeshGraphLocation location, ref NativeList<Edge<NavMeshGraphLocation>> edgeBuffer)
Parameters
| Type | Name | Description |
|---|---|---|
| NavMeshGraphLocation | location | |
| NativeList<Edge<NavMeshGraphLocation>> | edgeBuffer | Add edges to other nodes to this buffer. The buffer is automatically cleared each time before this method is called. Warning: do not modify the edgeBuffer itself. Only add to it. The ref keyword is only used for performance reasons. |
Dispose()
Declaration
public void Dispose()
Dispose(JobHandle)
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | inputDeps |
Returns
| Type | Description |
|---|---|
| JobHandle |
DrawOctreeGizmo()
Draws a gizmo of the structure of the internal octree. This can be used to determine an optimal max depth for the octree.
Declaration
public void DrawOctreeGizmo()
Remarks
This method is not included in a build, only use for debugging
DrawTrianglesGizmo()
Draws all triangles of the mesh.
Declaration
public void DrawTrianglesGizmo()
Remarks
This method is not included in a build, only use for debugging
GetAdjecency(int, out int, out int, out int)
Returns the adjecent triangle indexes of a triangle.
Declaration
public void GetAdjecency(int triangleIndex, out int triangleIndex1, out int triangleIndex2, out int triangleIndex3)
Parameters
| Type | Name | Description |
|---|---|---|
| int | triangleIndex | The triangle's index to get the adjecent triangles from. |
| int | triangleIndex1 | First adjecent triangle, -1 if none |
| int | triangleIndex2 | Second adjecent triangle, -1 if none |
| int | triangleIndex3 | Third adjecent triangle, -1 if none |
GetEnumerator()
Declaration
public NavMeshGraph.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| NavMeshGraph.Enumerator |
GetOverlappingTriangles(AABB, NativeHashSet<int>)
Appends the indices of all triangles whose AABB's overlap with a given AABB to the supplied NativeHashSet, so that no duplicates can occur
Declaration
public void GetOverlappingTriangles(AABB aabb, NativeHashSet<int> triangleIndices)
Parameters
| Type | Name | Description |
|---|---|---|
| AABB | aabb | The AABB |
| NativeHashSet<int> | triangleIndices | The set to append the triangle indices to, note that this set is not cleared beforehand |
Remarks
The indices that are returned are the starting indices of each triangle. E.g. an index of zero corresponds to index 0, 1 and 2 in the mesh raw indices array. The full triangle location can be obtained with LocationFromTriangleIndex(int) or GetTriangle(int)
GetOverlappingTriangles(AABB, NativeList<int>)
Appends the indices of all triangles whose AABB's overlap with a given AABB to the supplied nativelist
Declaration
public void GetOverlappingTriangles(AABB aabb, NativeList<int> triangleIndices)
Parameters
| Type | Name | Description |
|---|---|---|
| AABB | aabb | The AABB |
| NativeList<int> | triangleIndices | The list to append the triangle indices to, note that this list is not cleared beforehand |
Remarks
The indices that are returned are the starting indices of each triangle. E.g. an index of zero corresponds to index 0, 1 and 2 in the mesh raw indices array. The full triangle location can be obtained with LocationFromTriangleIndex(int) or GetTriangle(int)
It's possible for duplicates to occur. To guarantuee no duplicates, use the GetOverlappingTriangles(AABB, NativeHashSet<int>) overload.
GetTriangle(int)
Returns a triangle by index
Declaration
public Triangle GetTriangle(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The index of the triangle |
Returns
| Type | Description |
|---|---|
| Triangle |
LocationFromTriangleIndex(int)
Returns a location at the center of a triangle.
Declaration
public NavMeshGraphLocation LocationFromTriangleIndex(int triangleIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | triangleIndex | The index of the triangle to derive a location from |
Returns
| Type | Description |
|---|---|
| NavMeshGraphLocation | A location which can be used for pathfinding queries |
Populate(NavMeshGraph)
Copies the contents of the source graph into this graph. This can be useful if you want almost the exact same graph but will apply small modifications using SetUnwalkable(int) or SetEnterCostAndFlags(int, EnterCostAndFlags) on this graph after populating it.
Declaration
public void Populate(NavMeshGraph source)
Parameters
| Type | Name | Description |
|---|---|---|
| NavMeshGraph | source | The source graph to copy |
Remarks
This method is burst compatible, meaning it can be used inside a job to populate the graph with high performance, if you need frequent updates.
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it. The source graph is allowed be in use though.
Populate(NativeArray<Vector3>, NativeArray<int>)
Populates the graph with data and calculates everything neccessary to perform pathfinding on the mesh
Declaration
public void Populate(NativeArray<Vector3> vertices, NativeArray<int> triangles)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<Vector3> | vertices | Vertices to use. Similar to how a Unity mesh is constructed. Note that an internal copy is made |
| NativeArray<int> | triangles | Array describing the triangles using the indices in the vertex array. Length must be a multiple of 3 as each set of 3 indices describres a triangle. Note that an internal copy is made |
Remarks
This method is burst compatible, meaning it can be used inside a job to populate the graph with high performance, if you need frequent updates.
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it.
Populate(NativeArray<Vector3>, NativeArray<int>, NativeArray<EnterCostAndFlags>)
Populates the graph with data and calculates everything neccessary to perform pathfinding on the mesh
Declaration
public void Populate(NativeArray<Vector3> vertices, NativeArray<int> triangles, NativeArray<NavMeshGraph.EnterCostAndFlags> enterCostAndFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<Vector3> | vertices | Vertices to use. Similar to how a Unity mesh is constructed. Note that an internal copy of the array is made |
| NativeArray<int> | triangles | Array describing the triangles using the indices in the vertex array. Length must be a multiple of 3 as each set of 3 indices describres a triangle. Note that an internal copy is made |
| NativeArray<NavMeshGraph.EnterCostAndFlags> | enterCostAndFlags | Array with cost and flags per triangle. Note that one triangle equals 3 indices in the triangles array. So index zero in this array corresponds to the first set of 3 in the triangles array. Length should be the amount of triangles. (triangles parameter's length divided by 3). Null is allowed for this parameter, and will assign no extra cost and flags to the triangles. |
Remarks
This method is burst compatible, meaning it can be used inside a job to populate the graph with high performance, if you need frequent updates.
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it.
Populate(NativeArray<Vector3>, NativeArray<int>, NativeArray<EnterCostAndFlags>, Matrix4x4)
Populates the graph with data and calculates everything neccessary to perform pathfinding on the mesh
Declaration
public void Populate(NativeArray<Vector3> vertices, NativeArray<int> triangles, NativeArray<NavMeshGraph.EnterCostAndFlags> enterCostAndFlags, Matrix4x4 localToWorldMatrix)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<Vector3> | vertices | Vertices to use. Similar to how a Unity mesh is constructed. |
| NativeArray<int> | triangles | Array describing the triangles using the indices in the vertex array. Length must be a multiple of 3 as each set of 3 indices describres a triangle |
| NativeArray<NavMeshGraph.EnterCostAndFlags> | enterCostAndFlags | Array with cost and flags per triangle. Note that one triangle equals 3 indices in the triangles array. So index zero in this array corresponds to the first set of 3 in the triangles array. Length should be the amount of triangles. (triangles parameter's length divided by 3). default is allowed for this parameter, and will assign no extra cost and flags to the triangles. |
| Matrix4x4 | localToWorldMatrix | The local to world matrix to use. This is useful if you want the navmesh to use world space coordinates. Use Matrix4x4.identity if the vertices are already in world space or if you want to keep the coordinates in the local space of the mesh. |
Remarks
This method is burst compatible, meaning it can be used inside a job to populate the graph with high performance, if you need frequent updates.
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it.
Populate(Vector3[], int[])
Populates the graph with data and calculates everything neccessary to perform pathfinding on the mesh
Declaration
public void Populate(Vector3[] vertices, int[] triangles)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | vertices | Vertices to use. Similar to how a Unity mesh is constructed. |
| int[] | triangles | Array describing the triangles using the indices in the vertex array. Length must be a multiple of 3 as each set of 3 indices describres a triangle. Note that an internal copy is made |
Raycast(Ray, out NavMeshGraphLocation)
Performs a raycast against the NavMesh and returns the closest node that was hit. This can then be used as the starting node for a pathfinding request. The node contains information about the triangle as well as the exact location the path should start.
Declaration
public bool Raycast(Ray ray, out NavMeshGraphLocation location)
Parameters
| Type | Name | Description |
|---|---|---|
| Ray | ray | The ray to cast |
| NavMeshGraphLocation | location | The node that can be used as part of a path finding request |
Returns
| Type | Description |
|---|---|
| bool | True if there was a hit |
RaycastTriangle(Ray, out Triangle, out float3)
Performs a raycast against the NavMesh and returns the closest triangle that was hit.
Declaration
public bool RaycastTriangle(Ray ray, out Triangle triangle, out float3 hitPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Ray | ray | Ray to cast |
| Triangle | triangle | The triangle that was hit |
| float3 | hitPoint | The point where the triangle was hit |
Returns
| Type | Description |
|---|---|
| bool | True if there was a hit |
SetEnterCostAndFlags(int, EnterCostAndFlags)
Overwrites the cost and flags for a triangle, which can be obtained via RaycastTriangle(Ray, out Triangle, out float3) or GetOverlappingTriangles(AABB, NativeList<int>).
This can be useful if you've made a copy of a graph and want to apply slight modifications to it, or want to exclude certain triangles from being walkable (essentialy removing them)
To make a triangle unwalkable, supply Unwalkable as a parameter. Note that the triangle still exists in the navmesh, so it will still be returned from a raycast query. But A* will never use them in a path.
Declaration
public void SetEnterCostAndFlags(int triangleIndex, NavMeshGraph.EnterCostAndFlags costAndFlags)
Parameters
| Type | Name | Description |
|---|---|---|
| int | triangleIndex | The index of the triangle |
| NavMeshGraph.EnterCostAndFlags | costAndFlags | The new cost and flags parameters for this triangle |
Remarks
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it.
SetUnwalkable(int)
Makes a triangle unwalkable. Making it impossible for A* to navigate through it. Note that the triangle still exists in the navmesh, so it will still be returned from a raycast query.
Declaration
public void SetUnwalkable(int triangleIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | triangleIndex | The index of the triangle, which can be obtained via RaycastTriangle(Ray, out Triangle, out float3) or GetOverlappingTriangles(AABB, NativeList<int>) |
Remarks
Note that this method writes to the graph and as such it should not be used while there are active pathfinding queries running on it.
If you're comfortable with the flags being overwritten, SetEnterCostAndFlags(int, EnterCostAndFlags) with Unwalkable is faster.