Course contentsShow
← Unity Game Development
Lesson 513 of 8288. Artificial IntelligenceFree lesson

Implementing Off-Mesh Links for Non-Linear Traversal

You will define specific jump or drop points to allow agents to navigate across disconnected sections of the game environment.

In this lesson, you will learn how to bridge disconnected navigation surfaces so your AI agents can jump, climb, or drop between separate NavMesh areas.

The Concept of Non-Linear Traversal

While NavMeshAgent excels at finding paths across continuous surfaces, it cannot cross gaps—like a ledge-to-ledge jump—because there is no physical geometry for the agent to calculate a path. Off-Mesh Links act as a manual bridge. By defining a start point and an end point in 3D space, you provide the Navigation system with a "teleportation" or "traversal" connection that it considers a valid part of the pathfinding graph.

Implementing the Link

You can implement these links in two ways: automatically via the OffMeshLink component or manually during runtime.

To use the component, simply attach an OffMeshLink component to a GameObject in your scene. Assign two empty GameObjects as your Start and End transforms. When your NavMesh is baked, the system recognizes these points. If an agent’s path requires moving from the Start transform to the End transform, it will initiate the link traversal.

// Simple check to see if an agent is currently using a link
if (agent.isOnOffMeshLink)
{
    // You can trigger animations here, like a jump or climb
    Debug.Log("Agent is currently traversing a non-linear link!");
    
    // Complete the traversal
    agent.CompleteOffMeshLink();
}

Navigating the Gap

When an agent reaches an OffMeshLink, it doesn't automatically move its transform across the gap like a simple teleport. Instead, it pauses the pathfinding logic. You must either manually move the agent's transform using a Coroutine or a Tween to create a smooth jumping animation, or set the agent to kinematic mode to handle the movement via physics. Once the agent arrives at the destination point, calling CompleteOffMeshLink() informs the navigation system that the agent is ready to resume standard pathfinding on the new mesh surface.

This approach transforms your world from a series of flat, connected polygons into a dynamic environment where verticality and structural gaps are fully navigable by your AI.

Key Takeaway: Off-Mesh Links serve as explicit logical connections that bridge discontinuous NavMesh surfaces, allowing AI to navigate complex, non-linear architectural gaps.