A* Pathfinding Project  4.1.20
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
NavmeshBase Class Referenceabstract

Base class for RecastGraph and NavMeshGraph. More...

Detailed Description

Base class for RecastGraph and NavMeshGraph.

Public Member Functions

 NavmeshBase ()
 
abstract GraphTransform CalculateTransform ()
 Returns a new transform which transforms graph space to world space.
 
void EndBatchTileUpdate ()
 End batch updating of tiles.
 
override NNInfoInternal GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint)
 Returns the nearest node to a position using the specified NNConstraint.
 
override NNInfoInternal GetNearestForce (Vector3 position, NNConstraint constraint)
 Returns the nearest node to a position using the specified constraint .
 
override void GetNodes (System.Action< GraphNode > action)
 Calls a delegate with all nodes in the graph.
 
NavmeshTile GetTile (int x, int z)
 Tile at the specified x, z coordinate pair.
 
Bounds GetTileBounds (IntRect rect)
 Returns a bounds object with the bounding box of a group of tiles.
 
Bounds GetTileBounds (int x, int z, int width=1, int depth=1)
 Returns a bounds object with the bounding box of a group of tiles.
 
Bounds GetTileBoundsInGraphSpace (IntRect rect)
 
Bounds GetTileBoundsInGraphSpace (int x, int z, int width=1, int depth=1)
 Returns an XZ bounds object with the bounds of a group of tiles in graph space.
 
void GetTileCoordinates (int tileIndex, out int x, out int z)
 Tile coordinates from a tile index.
 
Int2 GetTileCoordinates (Vector3 position)
 Returns the tile coordinate which contains the specified position.
 
NavmeshTile[] GetTiles ()
 All tiles.
 
IntRect GetTouchingTiles (Bounds bounds)
 Returns a rect containing the indices of all tiles touching the specified bounds.
 
IntRect GetTouchingTilesInGraphSpace (Rect rect)
 Returns a rect containing the indices of all tiles touching the specified bounds.
 
IntRect GetTouchingTilesRound (Bounds bounds)
 Returns a rect containing the indices of all tiles by rounding the specified bounds to tile borders.
 
Int3 GetVertex (int index)
 Vertex coordinate for the specified vertex index.
 
int GetVertexArrayIndex (int index)
 
Int3 GetVertexInGraphSpace (int index)
 Vertex coordinate in graph space for the specified vertex index.
 
bool Linecast (Vector3 origin, Vector3 end)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 origin, Vector3 end, GraphNode hint)
 Returns if there is an obstacle between origin and end on the graph.
 
bool Linecast (Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace)
 Returns if there is an obstacle between origin and end on the graph.
 
override void OnDrawGizmos (Pathfinding.Util.RetainedGizmos gizmos, bool drawNodes)
 
GraphNode PointOnNavmesh (Vector3 position, NNConstraint constraint)
 Finds the first node which contains position.
 
override void RelocateNodes (Matrix4x4 deltaMatrix)
 Moves the nodes in this graph.
 
void RelocateNodes (GraphTransform newTransform)
 Moves the nodes in this graph.
 
void ReplaceTile (int x, int z, Int3[] verts, int[] tris)
 Replace tile at index with nodes created from specified navmesh.
 
void StartBatchTileUpdate ()
 Start batch updating of tiles.
 
- Public Member Functions inherited from NavGraph
virtual int CountNodes ()
 Number of nodes in the graph.
 
NNInfoInternal GetNearest (Vector3 position)
 Returns the nearest node to a position.
 
NNInfoInternal GetNearest (Vector3 position, NNConstraint constraint)
 Returns the nearest node to a position using the specified NNConstraint.
 
void GetNodes (System.Func< GraphNode, bool > action)
 Calls a delegate with all nodes in the graph until the delegate returns false.
 
virtual void OnDrawGizmos (RetainedGizmos gizmos, bool drawNodes)
 Draw gizmos for the graph.
 
void RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix)
 Moves nodes in this graph.
 
void Scan ()
 Scan the graph.
 
void ScanGraph ()
 Scan the graph.
 
void SetMatrix (Matrix4x4 m)
 Use to set both matrix and inverseMatrix at the same time.
 
- Public Member Functions inherited from IGraphInternals
void DeserializeExtraInfo (GraphSerializationContext ctx)
 
void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 
void DestroyAllNodes ()
 
void OnDestroy ()
 
void PostDeserialization (GraphSerializationContext ctx)
 
IEnumerable< ProgressScanInternal ()
 
void SerializeExtraInfo (GraphSerializationContext ctx)
 
- Public Member Functions inherited from INavmesh
void GetNodes (System.Action< GraphNode > del)
 
- Public Member Functions inherited from INavmeshHolder
void GetTileCoordinates (int tileIndex, out int x, out int z)
 Transforms coordinates from graph space to world space.
 
Int3 GetVertex (int i)
 Position of vertex number i in the world.
 
int GetVertexArrayIndex (int index)
 
Int3 GetVertexInGraphSpace (int i)
 Position of vertex number i in coordinates local to the graph.
 

Static Public Member Functions

static int GetTileIndex (int index)
 Tile index from a vertex index.
 
static bool Linecast (NavmeshBase graph, Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit)
 Returns if there is an obstacle between origin and end on the graph.
 
static bool Linecast (NavmeshBase graph, Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace)
 Returns if there is an obstacle between origin and end on the graph.
 

Public Attributes

bool enableNavmeshCutting = true
 Should navmesh cuts affect this graph.
 
Vector3 forcedBoundsSize = new Vector3(100, 40, 100)
 Size of the bounding box.
 
bool nearestSearchOnlyXZ
 Perform nearest node searches in XZ space only.
 
System.Action< NavmeshTile[]> OnRecalculatedTiles
 Called when tiles have been completely recalculated.
 
bool showMeshOutline = true
 Show an outline of the polygons in the Unity Editor.
 
bool showMeshSurface
 Show the surface of the navmesh.
 
bool showNodeConnections
 Show the connections between the polygons in the Unity Editor.
 
const int TileIndexMask = 0x7FFFF
 
const int TileIndexOffset = 12
 
int tileXCount
 Number of tiles along the X-axis.
 
int tileZCount
 Number of tiles along the Z-axis.
 
GraphTransform transform = GraphTransform.identityTransform
 Determines how the graph transforms graph space to world space.
 
const int VertexIndexMask = 0xFFF
 
- Public Attributes inherited from NavGraph
AstarPath active
 Reference to the AstarPath object in the scene.
 
bool drawGizmos = true
 Enable to draw gizmos in the Unity scene view.
 
uint graphIndex
 Index of the graph, used for identification purposes.
 
Guid guid
 Used as an ID of the graph, considered to be unique.
 
bool infoScreenOpen
 Used in the editor to check if the info screen is open.
 
uint initialPenalty
 Default penalty to apply to all nodes.
 
Matrix4x4 inverseMatrix = Matrix4x4.identity
 Inverse of matrix.
 
Matrix4x4 matrix = Matrix4x4.identity
 A matrix for translating/rotating/scaling the graph.
 
string name
 Name of the graph.
 
bool open
 Is the graph open in the editor.
 

Protected Member Functions

void ClearTile (int x, int z)
 Clear the tile at the specified coordinate.
 
void ConnectTiles (NavmeshTile tile1, NavmeshTile tile2)
 Generate connections between the two tiles.
 
void ConnectTileWithNeighbours (NavmeshTile tile, bool onlyUnflagged=false)
 
void CreateNodes (TriangleMeshNode[] buffer, int[] tris, int tileIndex, uint graphIndex)
 
override void DeserializeExtraInfo (GraphSerializationContext ctx)
 Deserializes graph type specific node data.
 
void FillWithEmptyTiles ()
 Fills graph with tiles created by NewEmptyTile.
 
NavmeshTile NewEmptyTile (int x, int z)
 Creates a single new empty tile.
 
override void OnDestroy ()
 Function for cleaning up references.
 
override void PostDeserialization (GraphSerializationContext ctx)
 Called after all deserialization has been done for all graphs.
 
void RemoveConnectionsFromTile (NavmeshTile tile)
 
void RemoveConnectionsFromTo (NavmeshTile a, NavmeshTile b)
 
override void SerializeExtraInfo (GraphSerializationContext ctx)
 Serializes Node Info.
 
- Protected Member Functions inherited from NavGraph
virtual void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 An old format for serializing settings.
 
virtual void DestroyAllNodes ()
 Destroys all nodes in the graph.
 
void DrawUnwalkableNodes (float size)
 
abstract IEnumerable< ProgressScanInternal ()
 Internal method to scan the graph.
 

Static Protected Member Functions

static void CreateNodeConnections (TriangleMeshNode[] nodes)
 Create connections between all nodes.
 

Protected Attributes

NavmeshTile[] tiles
 All tiles.
 

Package Attributes

readonly
NavmeshUpdates.NavmeshUpdateSettings 
navmeshUpdateData
 Handles navmesh cutting.
 

Properties

abstract float MaxTileConnectionEdgeDistance [get]
 Maximum (vertical) distance between the sides of two nodes for them to be connected across a tile edge.
 
abstract bool RecalculateNormals [get]
 Determines how normals are calculated.
 
abstract float TileWorldSizeX [get]
 Size of a tile in world units along the X axis.
 
abstract float TileWorldSizeZ [get]
 Size of a tile in world units along the Z axis.
 
GraphTransform ITransformedGraph. transform [get]
 
- Properties inherited from NavGraph
bool exists [get]
 True if the graph exists, false if it has been destroyed.
 
string IGraphInternals. SerializedEditorSettings [get, set]
 
- Properties inherited from IGraphInternals
string SerializedEditorSettings [get, set]
 
- Properties inherited from ITransformedGraph
GraphTransform transform [get]
 

Private Member Functions

void CreateNavmeshSurfaceVisualization (NavmeshTile tile, GraphGizmoHelper helper)
 Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor.
 
void DestroyNodes (List< MeshNode > nodes)
 Destroy several nodes simultaneously.
 
void PrepareNodeRecycling (int x, int z, Int3[] verts, int[] tris, TriangleMeshNode[] recycledNodeBuffer)
 Reuse nodes that keep the exact same vertices after a tile replacement.
 
void TryConnect (int tileIdx1, int tileIdx2)
 

Static Private Member Functions

static NavmeshBase ()
 
static void CreateNavmeshOutlineVisualization (NavmeshTile tile, GraphGizmoHelper helper)
 Creates an outline of the navmesh for use in OnDrawGizmos in the editor.
 

Private Attributes

List< MeshNodebatchNodesToDestroy = new List<MeshNode>()
 List of nodes that are going to be destroyed as part of a batch update.
 
bool batchTileUpdate
 Currently updating tiles in a batch.
 
List< int > batchUpdatedTiles = new List<int>()
 List of tiles updating during batch.
 
Dictionary< int, int > nodeRecyclingHashBuffer = new Dictionary<int, int>()
 Temporary buffer used in PrepareNodeRecycling.
 

Static Private Attributes

static readonly byte[] LinecastShapeEdgeLookup
 Used to optimize linecasts by precomputing some values.
 
static readonly NNConstraint NNConstraintDistanceXZ = new NNConstraint { distanceXZ = true }
 
static readonly NNConstraint NNConstraintNone = NNConstraint.None
 Cached NNConstraint.None to reduce allocations.
 

Constructor & Destructor Documentation

static NavmeshBase ( )
staticprivate

Member Function Documentation

abstract GraphTransform CalculateTransform ( )
pure virtual

Returns a new transform which transforms graph space to world space.

Does not update the transform field.

See Also
RelocateNodes(GraphTransform)

Implemented in RecastGraph, and NavMeshGraph.

void ClearTile ( int  x,
int  z 
)
protected

Clear the tile at the specified coordinate.

Must be called during a batch update, see StartBatchTileUpdate.

void ConnectTiles ( NavmeshTile  tile1,
NavmeshTile  tile2 
)
protected

Generate connections between the two tiles.

The tiles must be adjacent.

void ConnectTileWithNeighbours ( NavmeshTile  tile,
bool  onlyUnflagged = false 
)
protected
static void CreateNavmeshOutlineVisualization ( NavmeshTile  tile,
GraphGizmoHelper  helper 
)
staticprivate

Creates an outline of the navmesh for use in OnDrawGizmos in the editor.

void CreateNavmeshSurfaceVisualization ( NavmeshTile  tile,
GraphGizmoHelper  helper 
)
private

Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor.

static void CreateNodeConnections ( TriangleMeshNode[]  nodes)
staticprotected

Create connections between all nodes.

Version
Since 3.7.6 the implementation is thread safe
void CreateNodes ( TriangleMeshNode[]  buffer,
int[]  tris,
int  tileIndex,
uint  graphIndex 
)
protected
override void DeserializeExtraInfo ( GraphSerializationContext  ctx)
protectedvirtual

Deserializes graph type specific node data.

See Also
SerializeExtraInfo

Reimplemented from NavGraph.

void DestroyNodes ( List< MeshNode nodes)
private

Destroy several nodes simultaneously.

This is faster than simply looping through the nodes and calling the node.Destroy method because some optimizations relating to how connections are removed can be optimized.

void EndBatchTileUpdate ( )

End batch updating of tiles.

During batch updating, tiles will not be connected if they are updating with ReplaceTile. When ending batching, all affected tiles will be connected. This is faster than not using batching.

void FillWithEmptyTiles ( )
protected

Fills graph with tiles created by NewEmptyTile.

override NNInfoInternal GetNearest ( Vector3  position,
NNConstraint  constraint,
GraphNode  hint 
)
virtual

Returns the nearest node to a position using the specified NNConstraint.

Parameters
positionThe position to try to find a close node to
hintCan be passed to enable some graph generators to find the nearest node faster.
constraintCan for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce.

Reimplemented from NavGraph.

override NNInfoInternal GetNearestForce ( Vector3  position,
NNConstraint  constraint 
)
virtual

Returns the nearest node to a position using the specified constraint .

Returns
an NNInfo. This method will only return an empty NNInfo if there are no nodes which comply with the specified constraint.

Reimplemented from NavGraph.

override void GetNodes ( System.Action< GraphNode action)
virtual

Calls a delegate with all nodes in the graph.

This is the primary way of iterating through all nodes in a graph.

Do not change the graph structure inside the delegate.

var gg = AstarPath.active.data.gridGraph;
gg.GetNodes(node => {
// Here is a node
Debug.Log("I found a node at position " + (Vector3)node.position);
});

If you want to store all nodes in a list you can do this

var gg = AstarPath.active.data.gridGraph;
List<GraphNode> nodes = new List<GraphNode>();
gg.GetNodes((System.Action<GraphNode>)nodes.Add);

Implements NavGraph.

NavmeshTile GetTile ( int  x,
int  z 
)

Tile at the specified x, z coordinate pair.

The first tile is at (0,0), the last tile at (tileXCount-1, tileZCount-1).

var graph = AstarPath.active.data.recastGraph;
int tileX = 5;
int tileZ = 8;
NavmeshTile tile = graph.GetTile(tileX, tileZ);
for (int i = 0; i < tile.nodes.Length; i++) {
// ...
}
// or you can access the nodes like this:
tile.GetNodes(node => {
// ...
});
Bounds GetTileBounds ( IntRect  rect)

Returns a bounds object with the bounding box of a group of tiles.

The bounding box is defined in world space.

Bounds GetTileBounds ( int  x,
int  z,
int  width = 1,
int  depth = 1 
)

Returns a bounds object with the bounding box of a group of tiles.

The bounding box is defined in world space.

Bounds GetTileBoundsInGraphSpace ( IntRect  rect)
Bounds GetTileBoundsInGraphSpace ( int  x,
int  z,
int  width = 1,
int  depth = 1 
)

Returns an XZ bounds object with the bounds of a group of tiles in graph space.

void GetTileCoordinates ( int  tileIndex,
out int  x,
out int  z 
)

Tile coordinates from a tile index.

Int2 GetTileCoordinates ( Vector3  position)

Returns the tile coordinate which contains the specified position.

It is not necessarily a valid tile (i.e it could be out of bounds).

static int GetTileIndex ( int  index)
static

Tile index from a vertex index.

NavmeshTile [] GetTiles ( )

All tiles.

Warning
Do not modify this array
IntRect GetTouchingTiles ( Bounds  bounds)

Returns a rect containing the indices of all tiles touching the specified bounds.

IntRect GetTouchingTilesInGraphSpace ( Rect  rect)

Returns a rect containing the indices of all tiles touching the specified bounds.

Parameters
rectGraph space rectangle (in graph space all tiles are on the XZ plane regardless of graph rotation and other transformations, the first tile has a corner at the origin)
IntRect GetTouchingTilesRound ( Bounds  bounds)

Returns a rect containing the indices of all tiles by rounding the specified bounds to tile borders.

This is different from GetTouchingTiles in that the tiles inside the rectangle returned from this method may not contain the whole bounds, while that is guaranteed for GetTouchingTiles.

Int3 GetVertex ( int  index)

Vertex coordinate for the specified vertex index.

Exceptions
IndexOutOfRangeExceptionif the vertex index is invalid.
NullReferenceExceptionif the tile the vertex is in is not calculated.
See Also
NavmeshTile.GetVertex
int GetVertexArrayIndex ( int  index)
Int3 GetVertexInGraphSpace ( int  index)

Vertex coordinate in graph space for the specified vertex index.

bool Linecast ( Vector3  origin,
Vector3  end 
)

Returns if there is an obstacle between origin and end on the graph.

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  origin,
Vector3  end,
GraphNode  hint,
out GraphHitInfo  hit 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]originPoint to linecast from
[in]endPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintYou need to pass the node closest to the start point

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  origin,
Vector3  end,
GraphNode  hint 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]originPoint to linecast from
[in]endPoint to linecast to
[in]hintYou need to pass the node closest to the start point

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
bool Linecast ( Vector3  origin,
Vector3  end,
GraphNode  hint,
out GraphHitInfo  hit,
List< GraphNode trace 
)

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]originPoint to linecast from
[in]endPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintYou need to pass the node closest to the start point
traceIf a list is passed, then it will be filled with all nodes the linecast traverses

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
static bool Linecast ( NavmeshBase  graph,
Vector3  origin,
Vector3  end,
GraphNode  hint,
out GraphHitInfo  hit 
)
static

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]graphThe graph to perform the search on
[in]originPoint to start from
[in]endPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintYou need to pass the node closest to the start point, if null, a search for the closest node will be done

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
static bool Linecast ( NavmeshBase  graph,
Vector3  origin,
Vector3  end,
GraphNode  hint,
out GraphHitInfo  hit,
List< GraphNode trace 
)
static

Returns if there is an obstacle between origin and end on the graph.

Parameters
[in]graphThe graph to perform the search on
[in]originPoint to start from. This point should be on the navmesh. It will be snapped to the closest point on the navmesh otherwise.
[in]endPoint to linecast to
[out]hitContains info on what was hit, see GraphHitInfo
[in]hintIf you already know the node which contains the origin point, you may pass it here for slighly improved performance. If null, a search for the closest node will be done.
traceIf a list is passed, then it will be filled with all nodes along the line up until it hits an obstacle or reaches the end.

This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersections.

Note
This method only makes sense for graphs in which there is a definite 'up' direction. For example it does not make sense for e.g spherical graphs, navmeshes in which characters can walk on walls/ceilings or other curved worlds. If you try to use this method on such navmeshes it may output nonsense.
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here
NavmeshTile NewEmptyTile ( int  x,
int  z 
)
protected

Creates a single new empty tile.

override void OnDestroy ( )
protectedvirtual

Function for cleaning up references.

This will be called on the same time as OnDisable on the gameObject which the AstarPath script is attached to (remember, not in the editor). Use for any cleanup code such as cleaning up static variables which otherwise might prevent resources from being collected. Use by creating a function overriding this one in a graph class, but always call base.OnDestroy () in that function. All nodes should be destroyed in this function otherwise a memory leak will arise.

Reimplemented from NavGraph.

override void OnDrawGizmos ( Pathfinding.Util.RetainedGizmos  gizmos,
bool  drawNodes 
)
GraphNode PointOnNavmesh ( Vector3  position,
NNConstraint  constraint 
)

Finds the first node which contains position.

"Contains" is defined as position is inside the triangle node when seen from above. So only XZ space matters. In case of a multilayered environment, which node of the possibly several nodes containing the point is undefined.

Returns null if there was no node containing the point. This serves as a quick check for "is this point on the navmesh or not".

Note that the behaviour of this method is distinct from the GetNearest method. The GetNearest method will return the closest node to a point, which is not necessarily the one which contains it in XZ space.

See Also
GetNearest
override void PostDeserialization ( GraphSerializationContext  ctx)
protectedvirtual

Called after all deserialization has been done for all graphs.

Can be used to set up more graph data which is not serialized

Reimplemented from NavGraph.

void PrepareNodeRecycling ( int  x,
int  z,
Int3[]  verts,
int[]  tris,
TriangleMeshNode[]  recycledNodeBuffer 
)
private

Reuse nodes that keep the exact same vertices after a tile replacement.

The reused nodes will be added to the recycledNodeBuffer array at the index corresponding to the indices in the triangle array that its vertices uses.

All connections on the reused nodes will be removed except ones that go to other graphs. The reused nodes will be removed from the tile by replacing it with a null slot in the node array.

See Also
ReplaceTile
override void RelocateNodes ( Matrix4x4  deltaMatrix)
virtual

Moves the nodes in this graph.

Multiplies all node positions by deltaMatrix.

For example if you want to move all your nodes in e.g a point graph 10 units along the X axis from the initial position

var graph = AstarPath.data.pointGraph;
var m = Matrix4x4.TRS (new Vector3(10,0,0), Quaternion.identity, Vector3.one);
graph.RelocateNodes (m);
Note
For grid graphs, navmesh graphs and recast graphs it is recommended to use their custom overloads of the RelocateNodes method which take parameters for e.g center and nodeSize (and additional parameters) instead since they are both easier to use and are less likely to mess up pathfinding.
Warning
This method is lossy for PointGraphs, so calling it many times may cause node positions to lose precision. For example if you set the scale to 0 in one call then all nodes will be scaled/moved to the same point and you will not be able to recover their original positions. The same thing happens for other - less extreme - values as well, but to a lesser degree.

Reimplemented from NavGraph.

void RelocateNodes ( GraphTransform  newTransform)

Moves the nodes in this graph.

Moves all the nodes in such a way that the specified transform is the new graph space to world space transformation for the graph. You usually use this together with the CalculateTransform method.

So for example if you want to move and rotate all your nodes in e.g a recast graph you can do

var graph = AstarPath.data.recastGraph;
graph.rotation = new Vector3(45, 0, 0);
graph.forcedBoundsCenter = new Vector3(20, 10, 10);
var transform = graph.CalculateTransform();
graph.RelocateNodes(transform);

This will move all the nodes to new positions as if the new graph settings had been there from the start.

Note
RelocateNodes(deltaMatrix) is not equivalent to RelocateNodes(new GraphTransform(deltaMatrix)). The overload which takes a matrix multiplies all existing node positions with the matrix while this overload does not take into account the current positions of the nodes.
See Also
CalculateTransform
void RemoveConnectionsFromTile ( NavmeshTile  tile)
protected
void RemoveConnectionsFromTo ( NavmeshTile  a,
NavmeshTile  b 
)
protected
void ReplaceTile ( int  x,
int  z,
Int3[]  verts,
int[]  tris 
)

Replace tile at index with nodes created from specified navmesh.

This will create new nodes and link them to the adjacent tile (unless batching has been started in which case that will be done when batching ends).

The vertices are assumed to be in 'tile space', that is being in a rectangle with one corner at the origin and one at (TileWorldSizeX, 0, TileWorldSizeZ).

Note
The vertex and triangle arrays may be modified and will be stored with the tile data. do not modify them after this method has been called.
See Also
StartBatchTileUpdate
override void SerializeExtraInfo ( GraphSerializationContext  ctx)
protectedvirtual

Serializes Node Info.

Should serialize:

  • Base
    • Node Flags
    • Node Penalties
    • Node
  • Node Positions (if applicable)
  • Any other information necessary to load the graph in-game All settings marked with json attributes (e.g JsonMember) have already been saved as graph settings and do not need to be handled here.

It is not necessary for this implementation to be forward or backwards compatible.

See Also

Reimplemented from NavGraph.

void StartBatchTileUpdate ( )

Start batch updating of tiles.

During batch updating, tiles will not be connected if they are updating with ReplaceTile. When ending batching, all affected tiles will be connected. This is faster than not using batching.

void TryConnect ( int  tileIdx1,
int  tileIdx2 
)
private

Member Data Documentation

List<MeshNode> batchNodesToDestroy = new List<MeshNode>()
private

List of nodes that are going to be destroyed as part of a batch update.

bool batchTileUpdate
private

Currently updating tiles in a batch.

List<int> batchUpdatedTiles = new List<int>()
private

List of tiles updating during batch.

bool enableNavmeshCutting = true

Should navmesh cuts affect this graph.

See Also
navmeshUpdateData
Vector3 forcedBoundsSize = new Vector3(100, 40, 100)

Size of the bounding box.

readonly byte [] LinecastShapeEdgeLookup
staticprivate

Used to optimize linecasts by precomputing some values.

readonly NavmeshUpdates.NavmeshUpdateSettings navmeshUpdateData
package

Handles navmesh cutting.

See Also
enableNavmeshCutting
Pathfinding.NavmeshUpdates
bool nearestSearchOnlyXZ

Perform nearest node searches in XZ space only.

Recomended for single-layered environments. Faster but can be inaccurate esp. in multilayered contexts. You should not use this if the graph is rotated since then the XZ plane no longer corresponds to the ground plane.

This can be important on sloped surfaces. See the image below in which the closest point for each blue point is queried for:

You can also control this using a field on an NNConstraint object.

readonly NNConstraint NNConstraintDistanceXZ = new NNConstraint { distanceXZ = true }
staticprivate
readonly NNConstraint NNConstraintNone = NNConstraint.None
staticprivate

Cached NNConstraint.None to reduce allocations.

Dictionary<int, int> nodeRecyclingHashBuffer = new Dictionary<int, int>()
private

Temporary buffer used in PrepareNodeRecycling.

System.Action<NavmeshTile[]> OnRecalculatedTiles

Called when tiles have been completely recalculated.

This is called after scanning the graph and after performing graph updates that completely recalculate tiles (not ones that simply modify e.g penalties). It is not called after NavmeshCut updates.

bool showMeshOutline = true

Show an outline of the polygons in the Unity Editor.

bool showMeshSurface

Show the surface of the navmesh.

bool showNodeConnections

Show the connections between the polygons in the Unity Editor.

const int TileIndexMask = 0x7FFFF
const int TileIndexOffset = 12
NavmeshTile [] tiles
protected

All tiles.

See Also
GetTile
int tileXCount

Number of tiles along the X-axis.

int tileZCount

Number of tiles along the Z-axis.

Determines how the graph transforms graph space to world space.

See Also
CalculateTransform
Warning
Do not modify this directly, instead use e.g. RelocateNodes(GraphTransform)
const int VertexIndexMask = 0xFFF

Property Documentation

abstract float MaxTileConnectionEdgeDistance
getprotected

Maximum (vertical) distance between the sides of two nodes for them to be connected across a tile edge.

When tiles are connected to each other, the nodes sometimes do not line up perfectly so some allowance must be made to allow tiles that do not match exactly to be connected with each other.

abstract bool RecalculateNormals
getprotected

Determines how normals are calculated.

Disable for spherical graphs or other complicated surfaces that allow the agents to e.g walk on walls or ceilings.By default the normals of the mesh will be flipped so that they point as much as possible in the upwards direction. The normals are important when connecting adjacent nodes. Two adjacent nodes will only be connected if they are oriented the same way. This is particularly important if you have a navmesh on the walls or even on the ceiling of a room. Or if you are trying to make a spherical navmesh. If you do one of those things then you should set disable this setting and make sure the normals in your source mesh are properly set.If you for example take a look at the image below. In the upper case then the nodes on the bottom half of the mesh haven't been connected with the nodes on the upper half because the normals on the lower half will have been modified to point inwards (as that is the direction that makes them face upwards the most) while the normals on the upper half point outwards. This causes the nodes to not connect properly along the seam. When this option is set to false instead the nodes are connected properly as in the original mesh all normals point outwards.

The default value of this field is true to reduce the risk for errors in the common case. If a mesh is supplied that has all normals pointing downwards and this option is false, then some methods like PointOnNavmesh will not work correctly as they assume that the normals point upwards. For a more complicated surface like a spherical graph those methods make no sense anyway as there is no clear definition of what it means to be "inside" a triangle when there is no clear up direction.

abstract float TileWorldSizeX
get

Size of a tile in world units along the X axis.

abstract float TileWorldSizeZ
get

Size of a tile in world units along the Z axis.

GraphTransform ITransformedGraph. transform
getprivate

The documentation for this class was generated from the following file: