SetDestination can only be called on an active agent that has been placed on a NavMesh
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
The NavMeshAgent is not standing on a NavMesh it can use, or it is disabled, so it cannot plan a path. The agent snaps to the NavMesh when it is enabled; if there is no NavMesh close enough, it stays off it.
Read the Console line first
Select the agent in Play Mode. If it is not on the blue NavMesh overlay in the Scene view, that is the problem.
Common causes
There is no baked NavMesh
Add a NavMeshSurface component (from the AI Navigation package) and click Bake. Without a baked surface, no agent can path.
The agent spawned away from the mesh
Instantiating or moving an agent by setting transform.position can leave it off the mesh. Use NavMeshAgent.Warp, and NavMesh.SamplePosition to find the nearest valid point.
The agent is disabled or its GameObject is inactive
Calls on a disabled agent fail. Enable it first, or skip the call while it is disabled.
The agent type does not match the baked surface
A NavMeshSurface bakes for one agent type. An agent of another type cannot use it.
The fix
if (NavMesh.SamplePosition(spawnPoint, out var hit, 2f, NavMesh.AllAreas))
agent.Warp(hit.position);
if (agent.isActiveAndEnabled && agent.isOnNavMesh)
agent.SetDestination(target.position);Stop it coming back
Check agent.isOnNavMesh before path calls, and place spawned agents with Warp.
Questions
- The agent was on the NavMesh, then I moved it and the error started. Why?
- Setting
transform.positiondirectly can take the agent off the mesh. Move agents withagent.Warp(position), which places the agent on the NavMesh at that point. - How do I check before calling SetDestination?
- Test
agent.isActiveAndEnabled && agent.isOnNavMeshfirst. If it is false, wait a frame after spawning, or snap the spawn point withNavMesh.SamplePosition. - Where did the Navigation bake window go?
- Since Unity 2022.2, NavMesh baking belongs to the AI Navigation package: add a NavMeshSurface component to your level and press Bake. The old bake tab survives only as a deprecated window, so new projects should use NavMeshSurface.
Scripts that avoid it
- NavMesh Click-to-MoveClick-to-move character controller using NavMeshAgent. Click anywhere to navigate, with destination marker and path line.
- Enemy Chase AIEnemy AI that detects the player within radius, chases with line-of-sight, and returns to patrol when player escapes.
- Waypoint Patrol AI ProAdvanced patrol AI with NavMesh pathfinding, player detection with awareness meter, alert states, group coordination, and patrol schedules.
Related errors
Got a different error? Paste it into the error lookup.