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


The NavmeshCut component uses a 2D shape to cut the navmesh with. A rectangle and circle shape is built in, but you can also specify a custom mesh to use. 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.

Note that the shape is not 3D so if you rotate the cut you will see that the 2D shape will be rotated and then just projected down on the XZ plane.

To use a navmesh cut in your scene you need to have a TileHandlerHelper script somewhere in your scene. You should only have one though. That script will take care of checking all the NavmeshCut components to see if they need to update the navmesh.

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 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 extructed 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. This is a bit slower, but it is not a very large difference.

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.

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 Methods

ForceUpdate ()

Forces this navmesh cut to update the navmesh.

Public
GetContour (buffer)

World space contour of the navmesh cut.

Public
OnDrawGizmos ()
Public
OnDrawGizmosSelected ()
Public
RequiresUpdate ()

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

Public Enums

MeshType
Public

Inherited Public Members

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

Private/Protected Members

Awake ()
Protected
CalculateMeshContour ()
Private
contours
Private
edges

Cached variable, to avoid allocations.

Private Static Readonly
GetBounds (inverseTranform)

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

Package
GetY (transform)

Y coordinate of the center of the bounding box in graph space.

Package
lastMesh
Private
lastPosition
Private
lastRotation
Private
NotifyUpdated ()

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

Package
OnDisable ()
Protected
OnEnable ()
Protected
OnUpgradeSerializedData (version, unityThread)

Handle serialization backwards compatibility.

Protected
pointers

Cached variable, to avoid allocations.

Private Static Readonly
tr

cached transform component

Protected
TransformBuffer (buffer, reverse)
Private