A* Pathfinding Project  4.1.7
The A* Pathfinding Project for Unity 3D
RecastGraph Class Reference

Automatically generates navmesh graphs based on world geometry. More...

Detailed Description

Automatically generates navmesh graphs based on world geometry.

The recast graph is based on Recast (http://code.google.com/p/recastnavigation/).
I have translated a good portion of it to C# to run it natively in Unity.

How a recast graph works

When generating a recast graph what happens is that the world is voxelized. You can think of this as constructing an approximation of the world out of lots of boxes. If you have played Minecraft it looks very similar (but with smaller boxes).

The Recast process is described as follows:

  • The voxel mold is build from the input triangle mesh by rasterizing the triangles into a multi-layer heightfield. Some simple filters are then applied to the mold to prune out locations where the character would not be able to move.
  • The walkable areas described by the mold are divided into simple overlayed 2D regions. The resulting regions have only one non-overlapping contour, which simplifies the final step of the process tremendously.
  • The navigation polygons are peeled off from the regions by first tracing the boundaries and then simplifying them. The resulting polygons are finally converted to convex polygons which makes them perfect for pathfinding and spatial reasoning about the level.

It works exactly like that in the C# version as well, except that everything is triangulated to triangles instead of n-gons. The recast generation process usually works directly on the visiable geometry in the world, this is usually a good thing, because world geometry is usually more detailed than the colliders. You can however specify that colliders should be rasterized, if you have very detailed world geometry, this can speed up the scan.

Check out the second part of the Get Started Tutorial which discusses recast graphs.

Exporting for manual editing

In the editor there is a button for exporting the generated graph to a .obj file. Usually the generation process is good enough for the game directly, but in some cases you might want to edit some minor details. So you can export the graph to a .obj file, open it in your favourite 3D application, edit it, and export it to a mesh which Unity can import. You can then use that mesh in a navmesh graph.

Since many 3D modelling programs use different axis systems (unity uses X=right, Y=up, Z=forward), it can be a bit tricky to get the rotation and scaling right. For blender for example, what you have to do is to first import the mesh using the .obj importer. Don't change anything related to axes in the settings. Then select the mesh, open the transform tab (usually the thin toolbar to the right of the 3D view) and set Scale -> Z to -1. If you transform it using the S (scale) hotkey, it seems to set both Z and Y to -1 for some reason. Then make the edits you need and export it as an .obj file to somewhere in the Unity project. But this time, edit the setting named "Forward" to "Z forward" (not -Z as it is per default).

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

Public Types

enum  RelevantGraphSurfaceMode { DoNotRequire, OnlyForCompletelyInsideTile, RequireForAll }
 

Public Member Functions

override GraphTransform CalculateTransform ()
 Returns a new transform which transforms graph space to world space. More...
 
Vector3 ClosestPointOnNode (TriangleMeshNode node, Vector3 pos)
 Returns the closest point of the node. More...
 
bool ContainsPoint (TriangleMeshNode node, Vector3 pos)
 Returns if the point is inside the node in XZ space. More...
 
void SnapForceBoundsToScene ()
 Changes the bounds of the graph to precisely encapsulate all objects in the scene that can be included in the scanning process based on the settings. 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 an XZ bounds object with the bounds of a group of tiles. More...
 
Bounds GetTileBounds (int x, int z, int width=1, int depth=1)
 Returns an XZ bounds object with the bounds 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 ReplaceTile (int x, int z, int w, int d, Int3[] verts, int[] tris)
 Replaces a tile with a new mesh. 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 using the default NNConstraint. 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...
 

Public Attributes

const int BorderVertexMask = 1
 
const int BorderVertexOffset = 31
 
float cellSize = 0.5F
 Voxel sample size (x,z). More...
 
float characterRadius = 1.5F
 Radius of the agent which will traverse the navmesh. More...
 
float colliderRasterizeDetail = 10
 Controls detail on rasterization of sphere and capsule colliders. More...
 
float contourMaxError = 2F
 Max distance from simplified edge to real edge. More...
 
int editorTileSize = 128
 Size in voxels of a single tile. More...
 
Vector3 forcedBoundsCenter
 Center of the bounding box. More...
 
LayerMask mask = -1
 Layer mask which filters which objects to include. More...
 
float maxEdgeLength = 20
 Longer edges will be subdivided. More...
 
float maxSlope = 30
 Max slope in degrees the character can traverse. More...
 
float minRegionSize = 3
 Minumum region size. More...
 
bool rasterizeColliders
 Use colliders to calculate the navmesh. More...
 
bool rasterizeMeshes = true
 Use scene meshes to calculate the navmesh. More...
 
bool rasterizeTerrain = true
 Include the Terrain in the scene. More...
 
bool rasterizeTrees = true
 Rasterize tree colliders on terrains. More...
 
RelevantGraphSurfaceMode relevantGraphSurfaceMode = RelevantGraphSurfaceMode.DoNotRequire
 Require every region to have a RelevantGraphSurface component inside it. More...
 
Vector3 rotation
 Rotation of the graph in degrees. More...
 
bool scanEmptyGraph
 If true, scanning the graph will yield a completely empty graph. More...
 
List< string > tagMask = new List<string>()
 Objects tagged with any of these tags will be rasterized. More...
 
int terrainSampleSize = 3
 Controls how large the sample size for the terrain is. More...
 
int tileSizeX = 128
 Size of a tile along the X axis in voxels. More...
 
int tileSizeZ = 128
 Size of a tile along the Z axis in voxels. More...
 
bool useTiles = true
 If true, divide the graph into tiles, otherwise use a single tile covering the whole graph. More...
 
float walkableClimb = 0.5F
 Height the character can climb. More...
 
float walkableHeight = 2F
 Character height. 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

NavmeshTile BuildTileMesh (Voxelize vox, int x, int z, int threadIndex=0)
 
override void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 An old format for serializing settings. More...
 
IEnumerable< ProgressScanAllTiles ()
 
override IEnumerable< ProgressScanInternal ()
 Internal method to scan the graph. More...
 
- Protected Member Functions inherited from NavmeshBase
void ClearTiles (int x, int z, int w, int d)
 Clear all tiles within the rectangle with one corner at (x,z), width w and depth d. More...
 
void ConnectTiles (NavmeshTile tile1, NavmeshTile tile2)
 Generate connections between the two tiles. More...
 
void ConnectTileWithNeighbours (NavmeshTile tile, bool onlyUnflagged=false)
 
TriangleMeshNode [] CreateNodes (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

float CellHeight [get]
 
int CharacterRadiusInVoxels [get]
 Convert character radius to a number of voxels. More...
 
Bounds forcedBounds [get]
 World bounds for the graph. More...
 
override float MaxTileConnectionEdgeDistance [get]
 
override bool RecalculateNormals [get]
 
int TileBorderSizeInVoxels [get]
 Number of extra voxels on each side of a tile to ensure accurate navmeshes near the tile border. More...
 
float TileBorderSizeInWorldUnits [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...
 
- Properties inherited from ITransformedGraph
GraphTransform transform [get]
 

Private Member Functions

Bounds CalculateTileBoundsWithBorder (int x, int z)
 
GraphUpdateThreading IUpdatableGraph. CanUpdateAsync (GraphUpdateObject o)
 
List< RasterizationMeshCollectMeshes (Bounds bounds)
 
NavmeshTile CreateTile (Voxelize vox, VoxelMesh mesh, int x, int z, int threadIndex)
 Create a tile at tile index x, z from the mesh. More...
 
void InitializeTileInfo ()
 
List< RasterizationMesh > [] PutMeshesIntoTileBuckets (List< RasterizationMesh > meshes)
 Creates a list for every tile and adds every mesh that touches a tile to the corresponding list. More...
 
void IUpdatableGraph. UpdateArea (GraphUpdateObject guo)
 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 guo)
 Called on the Unity thread to complete a graph update. More...
 

Private Attributes

Voxelize globalVox
 
List< NavmeshTilestagingTiles = new List<NavmeshTile>()
 List of tiles that have been calculated in a graph update, but have not yet been added to the graph. More...
 

Additional Inherited Members

- 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...
 
- 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 Enumeration Documentation

◆ RelevantGraphSurfaceMode

Enumerator
DoNotRequire 

No RelevantGraphSurface components are required anywhere.

OnlyForCompletelyInsideTile 

Any surfaces that are completely inside tiles need to have a RelevantGraphSurface component positioned on that surface, otherwise it will be stripped away.

RequireForAll 

All surfaces need to have one RelevantGraphSurface component positioned somewhere on the surface and in each tile that it touches, otherwise it will be stripped away.

Only tiles that have a RelevantGraphSurface component for that surface will keep it.

Member Function Documentation

◆ BuildTileMesh()

NavmeshTile BuildTileMesh ( Voxelize  vox,
int  x,
int  z,
int  threadIndex = 0 
)
protected

◆ CalculateTileBoundsWithBorder()

Bounds CalculateTileBoundsWithBorder ( int  x,
int  z 
)
private

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

◆ ClosestPointOnNode()

Vector3 ClosestPointOnNode ( TriangleMeshNode  node,
Vector3  pos 
)

Returns the closest point of the node.

Deprecated:
Use Pathfinding.TriangleMeshNode.ClosestPointOnNode instead

◆ CollectMeshes()

List<RasterizationMesh> CollectMeshes ( Bounds  bounds)
private

◆ ContainsPoint()

bool ContainsPoint ( TriangleMeshNode  node,
Vector3  pos 
)

Returns if the point is inside the node in XZ space.

Deprecated:
Use Pathfinding.TriangleMeshNode.ContainsPoint instead

◆ CreateTile()

NavmeshTile CreateTile ( Voxelize  vox,
VoxelMesh  mesh,
int  x,
int  z,
int  threadIndex 
)
private

Create a tile at tile index x, z from the mesh.

Version
Since version 3.7.6 the implementation is thread safe

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

◆ InitializeTileInfo()

void InitializeTileInfo ( )
private

◆ PutMeshesIntoTileBuckets()

List<RasterizationMesh> [] PutMeshesIntoTileBuckets ( List< RasterizationMesh meshes)
private

Creates a list for every tile and adds every mesh that touches a tile to the corresponding list.

◆ ScanAllTiles()

IEnumerable<Progress> ScanAllTiles ( )
protected

◆ ScanInternal()

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.

◆ SnapForceBoundsToScene()

void SnapForceBoundsToScene ( )

Changes the bounds of the graph to precisely encapsulate all objects in the scene that can be included in the scanning process based on the settings.

Which objects are used depends on the settings. If an object would have affected the graph with the current settings if it would have been inside the bounds of the graph, it will be detected and the bounds will be expanded to contain that object.

This method corresponds to the 'Snap bounds to scene' button in the inspector.

See also
rasterizeMeshes
rasterizeTerrain
rasterizeColliders
mask
tagMask
forcedBoundsCenter
forcedBoundsSize

◆ UpdateArea()

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.

◆ 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  guo)
private

Called on the Unity thread to complete a graph update.

Implements IUpdatableGraph.

Member Data Documentation

◆ BorderVertexMask

const int BorderVertexMask = 1

◆ BorderVertexOffset

const int BorderVertexOffset = 31

◆ cellSize

float cellSize = 0.5F

Voxel sample size (x,z).

When generating a recast graph what happens is that the world is voxelized. You can think of this as constructing an approximation of the world out of lots of boxes. If you have played Minecraft it looks very similar (but with smaller boxes).

The cell size is the width and depth of those boxes. The height of the boxes is usually much smaller and automatically calculated however. See CellHeight.

Lower values will yield higher quality navmeshes, however the graph will be slower to scan.

◆ characterRadius

float characterRadius = 1.5F

Radius of the agent which will traverse the navmesh.

The navmesh will be eroded with this radius.

◆ colliderRasterizeDetail

float colliderRasterizeDetail = 10

Controls detail on rasterization of sphere and capsule colliders.

This controls the number of rows and columns on the generated meshes. A higher value does not necessarily increase quality of the mesh, but a lower value will often speed it up.

You should try to keep this value as low as possible without affecting the mesh quality since that will yield the fastest scan times.

See also
rasterizeColliders

◆ contourMaxError

float contourMaxError = 2F

Max distance from simplified edge to real edge.

This value is measured in voxels. So with the default value of 2 it means that the final navmesh contour may be at most 2 voxels (i.e 2 times cellSize) away from the border that was calculated when voxelizing the world. A higher value will yield a more simplified and cleaner navmesh while a lower value may capture more details. However a too low value will cause the individual voxels to be visible (see image below).

See also
cellSize

◆ editorTileSize

int editorTileSize = 128

Size in voxels of a single tile.

This is the width of the tile.

A large tile size can be faster to initially scan (but beware of out of memory issues if you try with a too large tile size in a large world) smaller tile sizes are (much) faster to update.

Different tile sizes can affect the quality of paths. It is often good to split up huge open areas into several tiles for better quality paths, but too small tiles can also lead to effects looking like invisible obstacles. For more information about this take a look at Notes about navmesh graphs. Usually it is best to experiment and see what works best for your game.

When scanning a recast graphs individual tiles can be calculated in parallel which can make it much faster to scan large worlds. When you want to recalculate a part of a recast graph, this can only be done on a tile-by-tile basis which means that if you often try to update a region of the recast graph much smaller than the tile size, then you will be doing a lot of unnecessary calculations. However if you on the other hand update regions of the recast graph that are much larger than the tile size then it may be slower than necessary as there is some overhead in having lots of tiles instead of a few larger ones (not that much though).

Recommended values are between 64 and 256, but these are very soft limits. It is possible to use both larger and smaller values.

◆ forcedBoundsCenter

Vector3 forcedBoundsCenter

Center of the bounding box.

Scanning will only be done inside the bounding box

◆ globalVox

Voxelize globalVox
private

◆ mask

LayerMask mask = -1

Layer mask which filters which objects to include.

See also
tagMask

◆ maxEdgeLength

float maxEdgeLength = 20

Longer edges will be subdivided.

Reducing this value can sometimes improve path quality since similarly sized triangles yield better paths than really large and really triangles small next to each other. However it will also add a lot more nodes which will make pathfinding slower. For more information about this take a look at Notes about navmesh graphs.

◆ maxSlope

float maxSlope = 30

Max slope in degrees the character can traverse.

◆ minRegionSize

float minRegionSize = 3

Minumum region size.

Small regions will be removed from the navmesh. Measured in square world units (square meters in most games).

If a region is adjacent to a tile border, it will not be removed even though it is small since the adjacent tile might join it to form a larger region.

◆ rasterizeColliders

bool rasterizeColliders

Use colliders to calculate the navmesh.

◆ rasterizeMeshes

bool rasterizeMeshes = true

Use scene meshes to calculate the navmesh.

◆ rasterizeTerrain

bool rasterizeTerrain = true

Include the Terrain in the scene.

◆ rasterizeTrees

bool rasterizeTrees = true

Rasterize tree colliders on terrains.

If the tree prefab has a collider, that collider will be rasterized. Otherwise a simple box collider will be used and the script will try to adjust it to the tree's scale, it might not do a very good job though so an attached collider is preferable.

Note
It seems that Unity will only generate tree colliders at runtime when the game is started. For this reason, this graph will not pick up tree colliders when scanned outside of play mode but it will pick them up if the graph is scanned when the game has started. If it still does not pick them up make sure that the trees actually have colliders attached to them and that the tree prefabs are in the correct layer (the layer should be included in the layer mask).
See also
rasterizeTerrain
colliderRasterizeDetail

◆ relevantGraphSurfaceMode

Require every region to have a RelevantGraphSurface component inside it.

A RelevantGraphSurface component placed in the scene specifies that the navmesh region it is inside should be included in the navmesh.

If this is set to OnlyForCompletelyInsideTile a navmesh region is included in the navmesh if it has a RelevantGraphSurface inside it, or if it is adjacent to a tile border. This can leave some small regions which you didn't want to have included because they are adjacent to tile borders, but it removes the need to place a component in every single tile, which can be tedious (see below).

If this is set to RequireForAll a navmesh region is included only if it has a RelevantGraphSurface inside it. Note that even though the navmesh looks continous between tiles, the tiles are computed individually and therefore you need a RelevantGraphSurface component for each region and for each tile.

In the above image, the mode OnlyForCompletelyInsideTile was used. Tile borders are highlighted in black. Note that since all regions are adjacent to a tile border, this mode didn't remove anything in this case and would give the same result as DoNotRequire. The RelevantGraphSurface component is shown using the green gizmo in the top-right of the blue plane.

In the above image, the mode RequireForAll was used. No tiles were used. Note that the small region at the top of the orange cube is now gone, since it was not the in the same region as the relevant graph surface component. The result would have been identical with OnlyForCompletelyInsideTile since there are no tiles (or a single tile, depending on how you look at it).

The mode RequireForAll was used here. Since there is only a single RelevantGraphSurface component, only the region it was in, in the tile it is placed in, will be enabled. If there would have been several RelevantGraphSurface in other tiles, those regions could have been enabled as well.

Here another tile size was used along with the OnlyForCompletelyInsideTile. Note that the region on top of the orange cube is gone now since the region borders do not intersect that region (and there is no RelevantGraphSurface component inside it).

Note
When not using tiles. OnlyForCompletelyInsideTile is equivalent to RequireForAll.

◆ rotation

Vector3 rotation

Rotation of the graph in degrees.

◆ scanEmptyGraph

bool scanEmptyGraph

If true, scanning the graph will yield a completely empty graph.

Useful if you want to replace the graph with a custom navmesh for example

◆ stagingTiles

List<NavmeshTile> stagingTiles = new List<NavmeshTile>()
private

List of tiles that have been calculated in a graph update, but have not yet been added to the graph.

When updating the graph in a separate thread, large changes cannot be made directly to the graph as other scripts might use the graph data structures at the same time in another thread. So the tiles are calculated, but they are not yet connected to the existing tiles that will be done in UpdateAreaPost which runs in the Unity thread.

◆ tagMask

List<string> tagMask = new List<string>()

Objects tagged with any of these tags will be rasterized.

Note that this extends the layer mask, so if you only want to use tags, set mask to 'Nothing'.

See also
mask

◆ terrainSampleSize

int terrainSampleSize = 3

Controls how large the sample size for the terrain is.

A higher value is faster to scan but less accurate

◆ tileSizeX

int tileSizeX = 128

Size of a tile along the X axis in voxels.

This is the width of the tile.

A large tile size can be faster to initially scan (but beware of out of memory issues if you try with a too large tile size in a large world) smaller tile sizes are (much) faster to update.

Different tile sizes can affect the quality of paths. It is often good to split up huge open areas into several tiles for better quality paths, but too small tiles can also lead to effects looking like invisible obstacles. For more information about this take a look at Notes about navmesh graphs. Usually it is best to experiment and see what works best for your game.

When scanning a recast graphs individual tiles can be calculated in parallel which can make it much faster to scan large worlds. When you want to recalculate a part of a recast graph, this can only be done on a tile-by-tile basis which means that if you often try to update a region of the recast graph much smaller than the tile size, then you will be doing a lot of unnecessary calculations. However if you on the other hand update regions of the recast graph that are much larger than the tile size then it may be slower than necessary as there is some overhead in having lots of tiles instead of a few larger ones (not that much though).

Recommended values are between 64 and 256, but these are very soft limits. It is possible to use both larger and smaller values.

Warning
Do not modify, it is set from editorTileSize at Scan
See also
tileSizeZ

◆ tileSizeZ

int tileSizeZ = 128

Size of a tile along the Z axis in voxels.

This is the width of the tile.

A large tile size can be faster to initially scan (but beware of out of memory issues if you try with a too large tile size in a large world) smaller tile sizes are (much) faster to update.

Different tile sizes can affect the quality of paths. It is often good to split up huge open areas into several tiles for better quality paths, but too small tiles can also lead to effects looking like invisible obstacles. For more information about this take a look at Notes about navmesh graphs. Usually it is best to experiment and see what works best for your game.

When scanning a recast graphs individual tiles can be calculated in parallel which can make it much faster to scan large worlds. When you want to recalculate a part of a recast graph, this can only be done on a tile-by-tile basis which means that if you often try to update a region of the recast graph much smaller than the tile size, then you will be doing a lot of unnecessary calculations. However if you on the other hand update regions of the recast graph that are much larger than the tile size then it may be slower than necessary as there is some overhead in having lots of tiles instead of a few larger ones (not that much though).

Recommended values are between 64 and 256, but these are very soft limits. It is possible to use both larger and smaller values.

Warning
Do not modify, it is set from editorTileSize at Scan
See also
tileSizeX

◆ useTiles

bool useTiles = true

If true, divide the graph into tiles, otherwise use a single tile covering the whole graph.

Since
Since 4.1 the default value is true.

◆ walkableClimb

float walkableClimb = 0.5F

Height the character can climb.

◆ walkableHeight

float walkableHeight = 2F

Character height.

Property Documentation

◆ CellHeight

float CellHeight
getprivate

◆ CharacterRadiusInVoxels

int CharacterRadiusInVoxels
getprivate

Convert character radius to a number of voxels.

◆ forcedBounds

Bounds forcedBounds
get

World bounds for the graph.

Defined as a bounds object with size forcedBoundsSize and centered at forcedBoundsCenter

Deprecated:
Obsolete since this is not accurate when the graph is rotated (rotation was not supported when this property was created)

◆ MaxTileConnectionEdgeDistance

override float MaxTileConnectionEdgeDistance
getprotected

◆ RecalculateNormals

override bool RecalculateNormals
getprotected

◆ TileBorderSizeInVoxels

int TileBorderSizeInVoxels
getprivate

Number of extra voxels on each side of a tile to ensure accurate navmeshes near the tile border.

The width of a tile is expanded by 2 times this value (1x to the left and 1x to the right)

◆ TileBorderSizeInWorldUnits

float TileBorderSizeInWorldUnits
getprivate

◆ TileWorldSizeX

override float TileWorldSizeX
get

◆ TileWorldSizeZ

override float TileWorldSizeZ
get

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