"SetDestination" can only be called on an active agent that has been placed on a NavMesh.

Whe I create a prefab with a navmesh agent in it, and drop it in a scene, I can programmatically set the destination with this code as a specific point in the game, and it goes to the destination.

Debug.Log (“Set Destination”);
meshagent = GetComponent();
meshagent.destination = target2.position;

however if i spawn using an instantiate with the prefab I get the following error when setting the destination and it does not go to the destination

“SetDestination” can only be called on an active agent that has been placed on a NavMesh.

Anyone any ideas

If you create a NavMeshAgent and set its position via transform.position=… and then try to SetDestination, it fails because the NavMeshAgent did not recognize the position change and does not know that it already is on the NavMesh. Use NavMeshAgent.Warp instead of transform.position to initialize the position before calling SetDestination.

I had the same issue…
In your scene click on a mesh or train and then in Window tabs select navigation…
Now u can see navigation layout beside the inspector…
Just in bake tab of navigation click the bottom button that says Bake…
And you’re done

5 year old issue, but since I was having this problem today I thought to add to this.

Make sure you use “humanoid” agent type. If you use custom type, you need to use NavMeshSurface by Unity.

See also here:

There‘s a possibility that the value of Agent Radius or Agent Height was set too small to not make Agent move;

I had the exact same problem but i solved it by moving the spawning position down a little bit so the navmesh agent spawned on the NavMesh, That way it did work for me.

make sure the prefab’s position is on the navmesh if you call GetComponent(NavMeshAgent) and SetDestination in Start(), since it’s called before you set its position.

I was also experiencing this issue after instantiating a prefab. I followed all the comments suggested above and none fixed my issue.

The GetComponent(NavMeshAgent) was being called in the Start() okay and capturing the agent. However, in the Update() method it wasn’t able to capture the agent. So I tagged the gameObject ‘Player’, and once I captured the gameObject found reference to its navmesh agent:

        players = GameObject.FindGameObjectsWithTag("Player");
		foreach (GameObject playerLoaded in players) {
			agent = playerLoaded.GetComponent<NavMeshAgent> ();

Hope this helps!

This can also occur if you delete the object. Haven’t found a solution to that yet.

I was using the empty transform object in which i had multiple spawn points.
The parent transform was set to 0,0,0(Reset) position which lied outside the navmesh.
This is my code.
IEnumerator Spawner()

    int spawnIndex = Random.Range(1, _enemySpawner.Length);
    if (_previousIndex != spawnIndex)
        GameObject zombie = Instantiate(_zombiePrefab, _enemySpawner[spawnIndex].position,_enemySpawner[spawnIndex].rotation);
        zombie.transform.parent = _enemySpawner[spawnIndex];
        yield return new WaitForSeconds(5);
    _previousIndex = spawnIndex;
    yield return null;

When you getComponentsInChildren,it also include the parent transform as well.
So you need to make sure not to spawn at parent transform which in my case lies outside the navmesh.
So I changed the random.Range from(0,_enemySpawner.Length) to Random.Range(1, _enemySpawner.Length);

Hope this help for those who are spawning at random places.

I had this same problem something that can also helps is NavMeshAgent.isOnNavMesh = true

 if (agent.isOnNavMesh)
            agent.destination = player.position;
            controller.SetBool("isWalking", true);

            //wait until we reached this position
            float remain = agent.remainingDistance;
            if(remain < .1)
                controller.SetBool("isWalking", false);
            Debug.Log("agent isOnNavMesh = " + agent.isOnNavMesh);


I hope this helps someone out there!

I thing radius and height property of your navmeshagent component are not set correctly…The values are not set correctly. If you set the angle value to 0.5, it should be a height of 2. … Consider this relationship.

Rebake the NavMesh on where the NavAgent will locate at should solve the ,Rebake the ground for NavMesh Should solve the problem

I know this post is a few years old and came across the same problem. What solved it for me was this post and I wanted to share it in case anyone else comes across this same error and the NavMeshAgent.Wrap doesn’t solve it:


I only can tell you is that notice the entity you are controlling. it must be in the tab of Hierarchy Not prefab!,HELLO fellas, i had this problem recently. I tried all above them to solve it, but i failed. Someday in sometimes. i finally find what is going on! that was a stupid mistake i’ve ever had. I took the PREFAB to my script to control instead of the entity! so in the script i was always letting the prefab to navMesh… so Unity told me these errors. i hope it can help someone who can’t solve the error using method above me.

I solved this by using the default Humanoid agent type with default values. I created my custom agent type but I started getting this error, when I switched back to Humanoid it was gone.

problem fixed here : SetDestination can only be called on an active agent that has been placed on a navmesh - YouTube