Class NavmeshCut Extends NavmeshClipper

Public

Navmesh cutting is used for fast recast/navmesh graph updates.

Navmesh cutting is used to cut holes into an existing navmesh generated by a recast or navmesh graph. Recast/navmesh graphs usually only allow either just changing parameters on existing nodes (e.g make a whole triangle unwalkable) which is not very flexible or recalculate a whole tile which is pretty slow. With navmesh cutting you can remove (cut) parts of the navmesh that is blocked by obstacles such as a new building in an RTS game however you cannot add anything new to the navmesh or change the positions of the nodes. This is significantly faster than recalculating whole tiles from scratch in a recast graph.

The NavmeshCut component uses a 2D shape to cut the navmesh with. This shape can be produced by either one of the built-in 2D shapes (rectangle/circle) or one of the 3D shapes (cube/sphere/capsule) which will be projected down to a 2D shape when cutting happens. You can also specify a custom 2D mesh to use as a cut.

Note that the rectangle/circle shapes are not 3D so if you rotate them you will see that the 2D shape will be rotated and then just projected down on the XZ plane. Therefore it is recommended to use the 3D shapes (cube/sphere/capsule) in most cases since those are easier to use.

In the scene view the NavmeshCut looks like an extruded 2D shape because a navmesh cut also has a height. It will only cut the part of the navmesh which it touches. For performance reasons it only checks the bounding boxes of the triangles in the navmesh, so it may cut triangles whoose bounding boxes it intersects even if the triangle does not intersect the extruded shape. However in most cases this does not make a large difference.

It is also possible to set the navmesh cut to dual mode by setting the isDual field to true. This will prevent it from cutting a hole in the navmesh and it will instead just split the navmesh along the border but keep both the interior and the exterior. This can be useful if you for example want to change the penalty of some region which does not neatly line up with the navmesh triangles. It is often combined with the GraphUpdateScene component (however note that the GraphUpdateScene component will not automatically reapply the penalty if the graph is updated again).

By default the navmesh cut does not take rotation or scaling into account. If you want to do that, you can set the useRotationAndScale field to true.

Version

In 3.x navmesh cutting could only be used with recast graphs, but in 4.x they can be used with both recast and navmesh graphs.

Custom meshes
For most purposes you can use the built-in shapes, however in some cases a custom cutting mesh may be useful. The custom mesh should be a flat 2D shape like in the image below. The script will then find the contour of that mesh and use that shape as the cut. Make sure that all normals are smooth and that the mesh contains no UV information. Otherwise Unity might split a vertex and then the script will not find the correct contour. You should not use a very high polygon mesh since that will create a lot of nodes in the navmesh graph and slow down pathfinding because of that. For very high polygon meshes it might even cause more suboptimal paths to be generated if it causes many thin triangles to be added to the navmesh.

Control updates through code
Navmesh cuts are applied periodically, but sometimes you may want to ensure the graph is up to date right now. Then you can use the following code. // Schedule pending updates to be done as soon as the pathfinding threads
// are done with what they are currently doing.
AstarPath.active.navmeshUpdates.ForceUpdate();
// Block until the updates have finished
AstarPath.active.FlushGraphUpdates();
You can also control how often the scripts check for if any navmesh cut has changed. If you have a very large number of cuts it may be good for performance to not check it as often. // Check every frame (the default)
AstarPath.active.navmeshUpdates.updateInterval = 0;

// Check every 0.1 seconds
AstarPath.active.navmeshUpdates.updateInterval = 0.1f;

// Never check for changes
AstarPath.active.navmeshUpdates.updateInterval = -1;
// You will have to schedule updates manually using
AstarPath.active.navmeshUpdates.ForceUpdate();
You can also find this setting in the AstarPath inspector under Settings.

Navmesh cutting and tags/penalties
Because navmesh cutting can modify the triangles in the navmesh pretty much abitrarily it is not possible to keep tags and penalties when updating the graph. The tags and penalties will be preserved for nodes which stay exactly the same when an update is applied though.

If you need to use tags, the only stable way to keep them is to apply all the graph updates that set them every time a navmesh cut update has been done. This is of course relatively slow, but it will at least work.

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

Inner Types

Public Methods

DrawGizmos ()
Public
ForceUpdate ()

Forces this navmesh cut to update the navmesh.

Public
GetBounds (inverseTransform, radiusMargin)

Bounds in XZ space after transforming using the *inverse* transform of the inverseTransform parameter.

Public
GetContour (buffer, matrix, radiusMargin)

Contour of the navmesh cut.

Public
GetContourBurst (outputVertices, outputContours, matrix, radiusMargin)

Contour of the navmesh cut.

Public
RequiresUpdate (previousState)

Returns true if this object has moved so much that it requires an update.

Public
UsedForCut ()

Called whenever this navmesh cut is used to update the navmesh.

Public

Public Variables

center
Public
circleRadius

Radius of the circle.

Public
circleResolution

Number of vertices on the circle.

Public
cutsAddedGeom

Cuts geometry added by a NavmeshAdd component.

Public
height

The cut will be extruded to this height.

Public
isDual

Only makes a split in the navmesh, but does not remove the geometry to make a hole.

Public
mesh

Custom mesh to use.

Public
meshScale

Scale of the custom mesh, if used.

Public
radiusExpansionMode

If the cut should be expanded by the agent radius or not.

Public
rectangleSize

Size of the rectangle.

Public
type

Shape of the cut.

Public
updateDistance

Distance between positions to require an update of the navmesh.

Public
updateRotationDistance

How many degrees rotation that is required for an update to the navmesh.

Public
useRotationAndScale

Includes rotation and scale in calculations.

Public

Public Static Variables

GizmoColor
Public Static Readonly
GizmoColor2
Public Static Readonly

Public Enums

MeshType
Public
RadiusExpansionMode
Public

Inherited Public Members

AddEnableCallback (onEnable, onDisable)
Public Static
RemoveEnableCallback (onEnable, onDisable)
Public Static
allEnabled

All navmesh clipper components in the scene.

Public Static
graphMask

Which graphs that are affected by this component.

Public

Private/Protected Members

Awake ()
Protected
CalculateMeshContour ()
Private
NotifyUpdated (previousState)

Internal method to notify the NavmeshCut that it has just been used to update the navmesh.

Internal
OnDisable ()
Protected
OnEnable ()
Protected
OnUpgradeSerializedData (migrations, unityThread)
Protected
OnUpgradeSerializedData (migrations, unityThread)

Handle serialization backwards compatibility.

Protected
Reset ()

Handle serialization backwards compatibility.

Protected
UpgradeSerializedData (isUnityThread)
Protected
contourTransformationMatrix
Private
edges

Cached variable, to avoid allocations.

Private Static Readonly
lastMesh
Private
meshContourVertices
Private
meshContours
Private
pointers

Cached variable, to avoid allocations.

Private Static Readonly
tr

cached transform component

Protected