A* Pathfinding Project  4.1.12
The A* Pathfinding Project for Unity 3D
NavmeshBase Class Referenceabstract

Base class for RecastGraph and NavMeshGraph. More...

Detailed Description

Base class for RecastGraph and NavMeshGraph.

Public Member Functions

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

Static Public Member Functions

static int GetTileIndex (int index)
 Tile index from a vertex index. More...
 
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. More...
 
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. More...
 

Public Attributes

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

Protected Member Functions

void ClearTile (int x, int z)
 Clear the tile at the specified coordinate. More...
 
void ConnectTiles (NavmeshTile tile1, NavmeshTile tile2)
 Generate connections between the two tiles. More...
 
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. More...
 
void FillWithEmptyTiles ()
 Fills graph with tiles created by NewEmptyTile. More...
 
NavmeshTile NewEmptyTile (int x, int z)
 Creates a single new empty tile. More...
 
override void OnDestroy ()
 Function for cleaning up references. More...
 
override void PostDeserialization (GraphSerializationContext ctx)
 Called after all deserialization has been done for all graphs. More...
 
void RemoveConnectionsFromTile (NavmeshTile tile)
 
void RemoveConnectionsFromTo (NavmeshTile a, NavmeshTile b)
 
override void SerializeExtraInfo (GraphSerializationContext ctx)
 Serializes Node Info. More...
 
- Protected Member Functions inherited from NavGraph
virtual void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 An old format for serializing settings. More...
 
virtual void DestroyAllNodes ()
 Destroys all nodes in the graph. More...
 
void DrawUnwalkableNodes (float size)
 
abstract IEnumerable< ProgressScanInternal ()
 Internal method to scan the graph. More...
 

Static Protected Member Functions

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

Protected Attributes

NavmeshTile [] tiles
 All tiles. More...
 

Properties

abstract float MaxTileConnectionEdgeDistance [get]
 Maximum (vertical) distance between the sides of two nodes for them to be connected across a tile edge. More...
 
abstract bool RecalculateNormals [get]
 Determines how normals are calculated. More...
 
abstract float TileWorldSizeX [get]
 Size of a tile in world units along the X axis. More...
 
abstract float TileWorldSizeZ [get]
 Size of a tile in world units along the Z axis. More...
 
GraphTransform ITransformedGraph. transform [get]
 
- Properties inherited from NavGraph
bool exists [get]
 True if the graph exists, false if it has been destroyed. More...
 
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. More...
 
void DestroyNodes (List< MeshNode > nodes)
 Destroy several nodes simultaneously. More...
 
void PrepareNodeRecycling (int x, int z, Int3[] verts, int[] tris, TriangleMeshNode[] recycledNodeBuffer)
 Reuse nodes that keep the exact same vertices after a tile replacement. More...
 
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. More...
 

Private Attributes

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

Static Private Attributes

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

Constructor & Destructor Documentation

◆ NavmeshBase()

static NavmeshBase ( )
staticprivate

Member Function Documentation

◆ CalculateTransform()

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.

◆ ClearTile()

void ClearTile ( int  x,
int  z 
)
protected

Clear the tile at the specified coordinate.

Must be called during a batch update, see StartBatchTileUpdate.

◆ ConnectTiles()

void ConnectTiles ( NavmeshTile  tile1,
NavmeshTile  tile2 
)
protected

Generate connections between the two tiles.

The tiles must be adjacent.

◆ ConnectTileWithNeighbours()

void ConnectTileWithNeighbours ( NavmeshTile  tile,
bool  onlyUnflagged = false 
)
protected

◆ CreateNavmeshOutlineVisualization()

static void CreateNavmeshOutlineVisualization ( NavmeshTile  tile,
GraphGizmoHelper  helper 
)
staticprivate

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

◆ CreateNavmeshSurfaceVisualization()

void CreateNavmeshSurfaceVisualization ( NavmeshTile  tile,
GraphGizmoHelper  helper 
)
private

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

◆ CreateNodeConnections()

static void CreateNodeConnections ( TriangleMeshNode []  nodes)
staticprotected

Create connections between all nodes.

Version
Since 3.7.6 the implementation is thread safe

◆ CreateNodes()

void CreateNodes ( TriangleMeshNode []  buffer,
int []  tris,
int  tileIndex,
uint  graphIndex 
)
protected

◆ DeserializeExtraInfo()

override void DeserializeExtraInfo ( GraphSerializationContext  ctx)
protectedvirtual

Deserializes graph type specific node data.

See also
SerializeExtraInfo

Reimplemented from NavGraph.

◆ DestroyNodes()

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.

◆ EndBatchTileUpdate()

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.

◆ FillWithEmptyTiles()

void FillWithEmptyTiles ( )
protected

Fills graph with tiles created by NewEmptyTile.

◆ GetNearest()

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.

◆ GetNearestForce()

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.

◆ GetNodes()

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.

◆ GetTile()

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 => {
// ...
});

◆ GetTileBounds() [1/2]

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.

◆ GetTileBounds() [2/2]

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.

◆ GetTileBoundsInGraphSpace() [1/2]

Bounds GetTileBoundsInGraphSpace ( IntRect  rect)

◆ GetTileBoundsInGraphSpace() [2/2]

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.

◆ GetTileCoordinates() [1/2]

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

Tile coordinates from a tile index.

Implements INavmeshHolder.

◆ GetTileCoordinates() [2/2]

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).

◆ GetTileIndex()

static int GetTileIndex ( int  index)
static

Tile index from a vertex index.

◆ GetTiles()

NavmeshTile [] GetTiles ( )

All tiles.

Warning
Do not modify this array

◆ GetTouchingTiles()

IntRect GetTouchingTiles ( Bounds  bounds)

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

◆ GetTouchingTilesInGraphSpace()

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)

◆ GetTouchingTilesRound()

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.

◆ GetVertex()

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

Implements INavmeshHolder.

◆ GetVertexArrayIndex()

int GetVertexArrayIndex ( int  index)

Implements INavmeshHolder.

◆ GetVertexInGraphSpace()

Int3 GetVertexInGraphSpace ( int  index)

Vertex coordinate in graph space for the specified vertex index.

Implements INavmeshHolder.

◆ Linecast() [1/6]

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

Implements IRaycastableGraph.

◆ Linecast() [2/6]

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

Implements IRaycastableGraph.

◆ Linecast() [3/6]

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

Implements IRaycastableGraph.

◆ Linecast() [4/6]

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

Implements IRaycastableGraph.

◆ Linecast() [5/6]

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

◆ Linecast() [6/6]

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

◆ NewEmptyTile()

NavmeshTile NewEmptyTile ( int  x,
int  z 
)
protected

Creates a single new empty tile.

◆ OnDestroy()

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.

◆ OnDrawGizmos()

override void OnDrawGizmos ( Pathfinding.Util.RetainedGizmos  gizmos,
bool  drawNodes 
)

◆ PointOnNavmesh()

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

◆ PostDeserialization()

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.

◆ PrepareNodeRecycling()

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

◆ RelocateNodes() [1/2]

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.

◆ RelocateNodes() [2/2]

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

◆ RemoveConnectionsFromTile()

void RemoveConnectionsFromTile ( NavmeshTile  tile)
protected

◆ RemoveConnectionsFromTo()

void RemoveConnectionsFromTo ( NavmeshTile  a,
NavmeshTile  b 
)
protected

◆ ReplaceTile()

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

◆ SerializeExtraInfo()

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.

◆ StartBatchTileUpdate()

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.

◆ TryConnect()

void TryConnect ( int  tileIdx1,
int  tileIdx2 
)
private

Member Data Documentation

◆ batchNodesToDestroy

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

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

◆ batchTileUpdate

bool batchTileUpdate
private

Currently updating tiles in a batch.

◆ batchUpdatedTiles

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

List of tiles updating during batch.

◆ forcedBoundsSize

Vector3 forcedBoundsSize = new Vector3(100, 40, 100)

Size of the bounding box.

◆ LinecastShapeEdgeLookup

readonly byte [] LinecastShapeEdgeLookup
staticprivate

Used to optimize linecasts by precomputing some values.

◆ nearestSearchOnlyXZ

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.

◆ NNConstraintDistanceXZ

readonly NNConstraint NNConstraintDistanceXZ = new NNConstraint { distanceXZ = true }
staticprivate

◆ NNConstraintNone

readonly NNConstraint NNConstraintNone = NNConstraint.None
staticprivate

Cached NNConstraint.None to reduce allocations.

◆ nodeRecyclingHashBuffer

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

Temporary buffer used in PrepareNodeRecycling.

◆ OnRecalculatedTiles

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.

◆ showMeshOutline

bool showMeshOutline = true

Show an outline of the polygons in the Unity Editor.

◆ showMeshSurface

bool showMeshSurface

Show the surface of the navmesh.

◆ showNodeConnections

bool showNodeConnections

Show the connections between the polygons in the Unity Editor.

◆ TileIndexMask

const int TileIndexMask = 0x7FFFF

◆ TileIndexOffset

const int TileIndexOffset = 12

◆ tiles

NavmeshTile [] tiles
protected

All tiles.

See also
GetTile

◆ tileXCount

int tileXCount

Number of tiles along the X-axis.

◆ tileZCount

int tileZCount

Number of tiles along the Z-axis.

◆ transform

GraphTransform transform = new GraphTransform(Matrix4x4.identity)

Determines how the graph transforms graph space to world space.

See also
CalculateTransform

◆ VertexIndexMask

const int VertexIndexMask = 0xFFF

Property Documentation

◆ MaxTileConnectionEdgeDistance

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.

◆ RecalculateNormals

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.

◆ TileWorldSizeX

abstract float TileWorldSizeX
get

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

◆ TileWorldSizeZ

abstract float TileWorldSizeZ
get

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

◆ transform

GraphTransform ITransformedGraph. transform
getprivate

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