Unity NavMesh (AI Navigation)
Give NPCs pathfinding in Unity 6.3 LTS: bake walkable surfaces and move agents around obstacles. Targets Unity 6.3 LTS (6000.3) with the AI Navigation package 2.x.
Version trap (Unity 2022+/6): the old built-in Navigation window (Object/Bake tabs) is gone. Baking is now component-based via the AI Navigation package (
com.unity.ai.navigation): add a NavMeshSurface to your level geometry and click Bake. The runtimeNavMeshAgent/NavMeshAPI stays in built-inUnityEngine.AI.
When to use
- Use when an agent needs to walk/chase/patrol to a target, when baking a navigable surface,
adding dynamic blockers (
NavMeshObstacle), or checking whether a destination is reachable. - Use when the project has the AI Navigation package, a
NavMeshSurfacecomponent, or scripts usingUnityEngine.AI.NavMeshAgent.
When not to use: the decision logic of when/where to move (FSMs, behaviour trees,
steering) → game-ai (this skill is the Unity movement/pathing mechanism). Force-driven or
kinematic movement that isn't pathfinding → unity-physics.
Core workflow
- Install the AI Navigation package (Package Manager →
com.unity.ai.navigation). - Bake a surface: select the static level geometry, Add Component → Navigation → NavMesh
Surface, set the agent type/area settings, and click Bake. Re-bake whenever geometry,
NavMeshModifiers, or agent settings change. - Add a
NavMeshAgentto each moving NPC; its radius/height/speed must match the baked agent type, and it must spawn on the baked mesh. - Drive it from script with
SetDestination(targetPos); the agent steers and avoids other agents automatically. Detect arrival withremainingDistance/pathPending. - Handle dynamic blockers with
NavMeshObstacle(carving) so closed doors/crates block paths without a full re-bake. - Verify with the AI Navigation overlay (the baked mesh is drawn in the Scene view) and by
watching agents path around obstacles to the goal; check
NavMeshPath.statusfor unreachable targets.
Patterns
1. Chase/seek with a NavMeshAgent
2. Check reachability before committing
3. Bake at runtime (for procedurally built or streamed levels)
4. Dynamic obstacle that carves the mesh
5. Connect separate mesh pieces with a NavMeshLink (jumps, doors, gaps)
Pitfalls
- Looking for the Navigation window — it no longer exists in Unity 6. Use the AI Navigation
package's
NavMeshSurfacecomponent + Bake. - Agent doesn't move / warps to origin — it isn't on the baked mesh, or no surface was
baked. Bake the surface and spawn the agent on it (
NavMesh.SamplePositionto snap). - Agent ignores new geometry — the navmesh is baked; runtime-spawned obstacles need a
NavMeshObstacle(carving) or asurface.BuildNavMesh()re-bake. SetDestinationevery frame is wasteful — for a slow-moving target, re-path on a timer (e.g. every 0.2s) instead of each frame.- Agent radius/height mismatch — if the
NavMeshAgent's size differs from the baked agent type, it gets stuck in gaps or floats; keep them consistent. - Agents jitter against each other — tune
avoidancePriorityand quality, or use an obstacle for truly static blockers rather than relying on agent avoidance. - Reaching for
OffMeshLink— the built-inOffMeshLinkcomponent is deprecated in AI Navigation 2.0 and can no longer be added from the Add Component menu. Use aNavMeshLink(from the package,Unity.AI.Navigation) instead — it adds Transform-based endpoints and a runtimeactivatedproperty. Migrate any existingOffMeshLinks. CalculatePathreturnsPathPartial— the destination sits on a different baked island than the agent (a gap the mesh doesn't cross). Bridge the two with aNavMeshLink(pattern 5) or extend the geometry so one surface covers both; a partial path only reaches the near edge.
References
- Primary docs: AI Navigation package manual
(
https://docs.unity3d.com/Packages/[email protected]/manual/index.html), theNavMeshLinkpage (https://docs.unity3d.com/Packages/[email protected]/manual/NavMeshLink.html) and its "What's new" note on theOffMeshLinkdeprecation (https://docs.unity3d.com/Packages/[email protected]/manual/whats-new.html), plusScriptReference/AI.NavMeshAgent,ScriptReference/AI.NavMesh.
Related skills
game-ai— engine-agnostic decision-making (FSM, behaviour trees, steering) that uses this.unity-csharp-scripting— the MonoBehaviour structure around the agent.tower-defense/fps-shooter— genres that compose pathfinding with gameplay.
