A* Pathfinding Project  4.1.12
The A* Pathfinding Project for Unity 3D
NavMeshGraph Class Reference

Generates graphs based on navmeshes. More...

Detailed Description

Generates graphs based on navmeshes.

Navmeshes are meshes where each triangle defines a walkable area. These are great because the AI can get so much more information on how it can walk. Polygons instead of points mean that the funnel smoother can produce really nice looking paths and the graphs are also really fast to search and have a low memory footprint because fewer nodes are usually needed to describe the same area compared to grid graphs.

See also
Pathfinding.RecastGraph

Public Member Functions

override GraphTransform CalculateTransform ()
 Returns a new transform which transforms graph space to world space. More...
 
void ScanInternal (string objMeshPath)
 Scans the graph using the path to an .obj mesh. More...
 
- Public Member Functions inherited from NavmeshBase
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 void UpdateArea (GraphUpdateObject o, INavmeshHolder graph)
 
- Static Public Member Functions inherited from NavmeshBase
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 offset
 Offset in world space. More...
 
bool recalculateNormals = true
 Determines how normals are calculated. More...
 
Vector3 rotation
 Rotation in degrees. More...
 
float scale = 1
 Scale of the graph. More...
 
Mesh sourceMesh
 Mesh to construct navmesh from. More...
 
- Public Attributes inherited from NavmeshBase
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

override void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 An old format for serializing settings. More...
 
override IEnumerable< ProgressScanInternal ()
 Internal method to scan the graph. More...
 
- Protected Member Functions inherited from NavmeshBase
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 DestroyAllNodes ()
 Destroys all nodes in the graph. More...
 
void DrawUnwalkableNodes (float size)
 

Properties

override float MaxTileConnectionEdgeDistance [get]
 
override bool RecalculateNormals [get]
 
override float TileWorldSizeX [get]
 
override float TileWorldSizeZ [get]
 
- Properties inherited from NavmeshBase
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

GraphUpdateThreading IUpdatableGraph. CanUpdateAsync (GraphUpdateObject o)
 
void IUpdatableGraph. UpdateArea (GraphUpdateObject o)
 Updates an area using the specified #GraphUpdateObject. More...
 
void IUpdatableGraph. UpdateAreaInit (GraphUpdateObject o)
 May be called on the Unity thread before starting the update. More...
 
void IUpdatableGraph. UpdateAreaPost (GraphUpdateObject o)
 May be called on the Unity thread after executing the update. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from NavmeshBase
static void CreateNodeConnections (TriangleMeshNode[] nodes)
 Create connections between all nodes. More...
 
- Protected Attributes inherited from NavmeshBase
NavmeshTile [] tiles
 All tiles. More...
 

Member Function Documentation

◆ CalculateTransform()

override GraphTransform CalculateTransform ( )
virtual

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

Does not update the transform field.

See also
RelocateNodes(GraphTransform)

Implements NavmeshBase.

◆ CanUpdateAsync()

GraphUpdateThreading IUpdatableGraph. CanUpdateAsync ( GraphUpdateObject  o)
private

Implements IUpdatableGraph.

◆ DeserializeSettingsCompatibility()

override void DeserializeSettingsCompatibility ( GraphSerializationContext  ctx)
protectedvirtual

An old format for serializing settings.

Deprecated:
This is deprecated now, but the deserialization code is kept to avoid loosing data when upgrading from older versions.

Reimplemented from NavGraph.

◆ ScanInternal() [1/2]

void ScanInternal ( string  objMeshPath)

Scans the graph using the path to an .obj mesh.

◆ ScanInternal() [2/2]

override IEnumerable<Progress> ScanInternal ( )
protectedvirtual

Internal method to scan the graph.

Called from AstarPath.ScanAsync. Override this function to implement custom scanning logic. Progress objects can be yielded to show progress info in the editor and to split up processing over several frames when using async scanning.

Implements NavGraph.

◆ UpdateArea() [1/2]

void IUpdatableGraph. UpdateArea ( GraphUpdateObject  o)
private

Updates an area using the specified #GraphUpdateObject.

Notes to implementators. This function should (in order):

  1. Call o.WillUpdateNode on the GUO for every node it will update, it is important that this is called BEFORE any changes are made to the nodes.
  2. Update walkabilty using special settings such as the usePhysics flag used with the GridGraph.
  3. Call Apply on the GUO for every node which should be updated with the GUO.
  4. Update connectivity info if appropriate (GridGraphs updates connectivity, but most other graphs don't since then the connectivity cannot be recovered later).

Implements IUpdatableGraph.

◆ UpdateArea() [2/2]

static void UpdateArea ( GraphUpdateObject  o,
INavmeshHolder  graph 
)
static

◆ UpdateAreaInit()

void IUpdatableGraph. UpdateAreaInit ( GraphUpdateObject  o)
private

May be called on the Unity thread before starting the update.

See also
CanUpdateAsync

Implements IUpdatableGraph.

◆ UpdateAreaPost()

void IUpdatableGraph. UpdateAreaPost ( GraphUpdateObject  o)
private

May be called on the Unity thread after executing the update.

See also
CanUpdateAsync

Implements IUpdatableGraph.

Member Data Documentation

◆ offset

Vector3 offset

Offset in world space.

◆ recalculateNormals

bool recalculateNormals = true

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.

◆ rotation

Vector3 rotation

Rotation in degrees.

◆ scale

float scale = 1

Scale of the graph.

◆ sourceMesh

Mesh sourceMesh

Mesh to construct navmesh from.

Property Documentation

◆ MaxTileConnectionEdgeDistance

override float MaxTileConnectionEdgeDistance
getprotected

◆ RecalculateNormals

override bool RecalculateNormals
getprotected

◆ TileWorldSizeX

override float TileWorldSizeX
get

◆ TileWorldSizeZ

override float TileWorldSizeZ
get

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