Create a NavMesh Link
Use NavMesh Links when you want to create paths that cross outside of the walkable navigation mesh surface. For example, you can set up NavMesh Links to allow agents to jump over a ditch or a fence, or to open a door before walking through it. To do this, you first need to add a NavMesh Link component to a GameObject in your scene. Then you position each end of the link at either a point in the scene or at the position of a GameObject that you choose to reference. When the ends are in place over the NavMesh, the Link creates a navigation connection that the NavMesh Agent can follow.
We’re going to add an NavMesh Link component to describe a jump from the upper platform to the ground.
- First create two cylinders: Game Object > 3D Object > Cylinder.
- Scale the cylinders to (0.1, 0.05, 0.1) to make it easier to work with them.
- Move the first cylinder to the edge of the top platform, close to the NavMesh surface.
- Place the second cylinder on the ground, close to the NavMesh, at the location where the link should land.
- Select the first cylinder and add a NavMesh Link component to it. In the inspector, select Add Component > Navigation > NavMesh Link.
- In the Start Transform field, assign the first cylinder.
- In the End Transform field, assign the second cylinder.
Now you have a functioning NavMesh Link set up. Pathfinding returns the path going through the NavMesh link if that path is shorter than walking along the NavMesh.
You can use any GameObject in the scene to hold the NavMesh link component, for example a fence prefab can contain the NavMesh link component. Similarly you can use any GameObject with a Transform as the start, or end, marker.
To learn about all the NavMesh Link properties that you can tweak, refer to the NavMesh Link component reference.
The NavMesh bake process can detect and create common jump-across and drop-down links automatically. Refer to the settings of NavMesh Surface for more details.
How to troubleshoot a link that does not work
If the agent does not traverse a NavMesh Link make sure that both end points are connected correctly to the NavMesh. To check the state of the connection make sure to enable the Show NavMesh debug visualization in the AI Navigation overlay. When the link has no width, a properly connected end point shows a circle around the access point in the scene view. If the link has width, the link shows a dark segment on the edge that connects properly to the NavMesh, or a gray line if the edge does not connect to the NavMesh. If both ends connect to the NavMesh, the wide link shows an additional solid transparent rectangle that fills the space between the link edges. The NavMesh link also shows an arc line between the ends, with an arrow at each end where the agent can exit the link. The arc line is colored black if at least one end is connected, or it is colored gray if none of the ends is connected to the NavMesh.
No agent or path can traverse a link that has the Activated property disabled. In that situation the link shows in the scene with a red color. Make sure to enable the Activated property when you want agents to be able to move through the link.
Another common cause of why an agent does not traverse a NavMesh Link is that the NavMesh Agent’s Area Mask does not include the NavMesh Link’s area type.