2

I'm getting this error in the editor

"SetDestination" can only be called on an active agent that has been placed on a NavMesh. These are the steps that I tried when solving the problem:

  1. Warping NavmeshAgent to the NavMesh location
  2. Manually moving the NavMeshAgent to NavMesh
  3. Rebaking the NavMesh and doing the steps above
  4. Creating a box with NavMeshAgent and a new NavMesh
    • does anyone have any other tips that I could use?
Luka Rolak
  • 43
  • 1
  • 7
  • Show the script you are using to connect the NavMesh to the NavMeshAgent – Programmer Sep 29 '17 at 19:38
  • This is the line that gives the error, nothing wrong with it, I used the same code millions of times before PlantAgent.SetDestination (Player.transform.position); PlantAgent is NavMeshAgent type – Luka Rolak Sep 29 '17 at 19:44
  • also that same code work in another project, but on this one, I can't set up a NavMesh for some reason – Luka Rolak Sep 29 '17 at 19:45
  • Is the NavMeshAgent component active? Show us some screenshots of the scene/properties. – Serlite Sep 29 '17 at 19:45
  • I checked everything, NavMesh is static, agent is active, I have the identical setup working in another project without a problem – Luka Rolak Sep 29 '17 at 19:47
  • I don't know how to help at this moment. Can you zip the project and upload it somewhere then send the link here. I will take a look at it – Programmer Sep 29 '17 at 20:16
  • Unfortunately, that would break my NDA. It's really a strange bug that I can't replicate in other projects. I've looked everywhere to some kind of API or function that would allow me to manually pair navmesh and navmesh agent but there is none. – Luka Rolak Sep 29 '17 at 20:44
  • Usually, you create a simple scene and try to replicate it. If you can't replicate it then that would be hard to fix. I am sure it's not a bug. It's a mistake on your side but who knows...I hope you find a fix for this. Post a solution when you find it – Programmer Sep 29 '17 at 21:09
  • "Where" did you warp your `NavMeshAgent` to? Could it be its too far above or below the `NavMesh`? Just a wild guess ... – yes Sep 29 '17 at 21:45

2 Answers2

4

Warping the Nav Mesh Agents position can sometimes cause errors, especially if it has gone from one navmesh to another.

It's a strange bug, but it seems detecting if the agent is not on the navmesh, and then disabling and re-enabling the agent - will fix the issue (it did in my case).

I've solved this in my project by doing the following when I warp.

//use some existing reference to your NavMeshAgent
NavMeshAgent agent = PlayerController.instance.GetComponent<NavMeshAgent>(); 

//This will fire when you get the error you're describing.
if (!agent.isOnNavMesh)
{
   Vector3 warpPosition; //Set to position you want to warp to
   agent.transform.position = warpPosition;
   agent.enabled = false;
   agent.enabled = true;
}
Bejasc
  • 930
  • 1
  • 8
  • 20
-2

we can use the navmesh component 1. navmesh surface 2. navmesh modifier 3. navmesh modifier volume 4. navmesh offlink by using these component we easily connect the navmesh and navmeshagent.