Can't get NavMeshAgent move. NavMeshAgent ignores destination property

Hi! I’m using Unity 4.0.0f7.
Now, I’m trying to be familliar with NavMeshes and NavMeshAgents.
I created a simple plane, made it Navigation Static, Baked it. Created Cube, added NavMeshAgent to it. Attached a script:

public var target:Transform;

function Update () {

GetComponent(NavMeshAgent).destination = target.position;
Debug.Log(GetComponent(NavMeshAgent).destination+" "+GetComponent(NavMeshAgent).pathStatus+" "+target.position);    
}

After first unlucky try, I’ve added to the script this construction: Debug.Log(Debug.Log(GetComponent(NavMeshAgent).destination) into Update() function.
Log says that navmesh totaly ignore my “GetComponent(NavMeshAgent).destination” construction.

“target” is simple capsule, placed on the opposide side of plane.
“pathStatus” says “PathComplete”.

7 Answers

7

Hello to everyone! I’ve finally figure out whats wrong! But I had never imagine, that this coud be reason! So when you Bake NavMesh from your geometry, there are some parameters. In “General” part, there are two parameters: “Radius” and “Height”. So, this parameters have nothig with NavMesh generation! Instead this parameters LIMITS NavMeshAgents, to work with this NavMesh. So If you want, that your NavMeshAgents travel over this NavMesh, you should place “Height” and “Radius” of the smallest of your NavMeshAgents into this NavMesh parameter before Baking.

You are correct, I had the same problem. But instead of making the NavMesh bake settings for radius and height smaller, I increased the size of my agent. It had to be small, so I kept the small mesh visible and parented it to a cube of big enough sizes and disabled that cube's MeshRenderer. Did the trick. Thanks.

In my case it was simply that the transform of the target was actually just outside the “Valid Y range” for the destination to “snap” to the NavMesh.

No easily discernible warning is offered in this instance. If the agent was too far from the mesh this would cause a: “SetDestination can only be called on an active agent that has been placed on a NavMesh.” when invoking a NavMesh related function (‘SetDestination’ in this example). However there is no immediate: “SetDestination can only be called on a position within /n/ of the NavMesh.”, it simply silently fails. Caveat discipulus!.

Not sure how wide a range that is yet, looks to be about “±12” just on basic testing.

Hope it helps someone else save some time. There are some helper functions to determine valid mesh points that I also have not explored. That too might be a sensible wrapper for this call.

Also sometimes when you play with NavMeshAgent speed, if you set it to 0 then you forget to set it back to a bigger value, in this case setDestination simple will not have any affect. So you should check this at first before checking other solutions.

Thank you sir. I have been messing with this on a few occasions! Was indeed the speed.

Hello, try to create an C# script and use this code:

public GameObject target;

// Update is called once per frame
void Update () {

	

this.gameObject.GetComponent<NavMeshAgent>().destination = target.transform.position;
	
}

put the script in your Cube agent. I used this code here and it worked. If this dosen’t work, you might have a problem with something else. If this work, you might need to check out how to access your NavMeshAgent component with Java script.
Hope this helped you! Take care.

First - thanks for answer. Second - no, even this script doesn't work... Attaching my Demo Project. The problem is in "scene2". This is Unity4 project. If you can, please check it, and tell me, whats my mistake? http://www.mediafire.com/?cq5q5ayiww56ia9 The project are clean. The are some simple models from Maya and Sketchup, but they are in "scene1"

This site made an error with the format of my code, the correct code linde inside Update is the one inside the image attached. Take Care.[9221-captura+de+tela+2013-03-22+às+18.46.04.png|9221]

Yes, I corrected code to exatly this. But it's still doesn't work...

Also, if you’re NavMesh Baking some sort of huge or extra scaled landscape, don’t forget to tune “Width inaccuracy %” and “Height inaccuracy %”, because they are controls how much diffrence can be between start point of your agents and destination!

Check if the y position is on the navmesh

Hey,if your navmesh agent is not moving in executable file or the actual game but works in editor then check your assets folder for multiple navmesh data.I had the same problem too,my navmesh agent was not moving in-game but was moving in-editor,i check my asset folder and find that i have multiple baked navmesh data so i deleted those and baked a new one and then it also started working in-game too so check for multiple navmesh data saved in your assest folder.
i just checked it in my game and i got the solution.
@mukund55