- Home /
Nav Mesh SetDestination can't be called
Hi,
I have a problem with Nav Mesh. There are two scenes, the first leads into the second.
In the first scene is:
A Character with a Nav Mesh Agent, and a second script from where I set the destination
A walkground with a baked NavMesh
A DontDestroyOnLoad() on the character and a trigger with Application.LoadLevel()
In the second scene:
Another Nav Mesh
A starting point object to which the undestroyed cahracter from the first scene is set, right on the Nav Mesh
When I play it, the first scene works great, the character is navigating through the entire scene. But when I come to the second scene and I click on the walkground I get this message:
"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.NavMeshAgent:set_destination(Vector3)
I have no idea what's the issue. I checked if the component is active, and it's active for sure. Also the character is just above the Nav Mesh.
Here is the code snipped, where the destination is set:
if(hit.collider.tag == walkTag){
print(GetComponent(NavMeshAgent)); //prints YES, IT HAS AN AGENT
print(GetComponent(NavMeshAgent).active); //AND YES, IT IS ACTIVE
GetComponent(NavMeshAgent).destination = hit.point;
}
Any advice?
Answer by Reapazor · Aug 13, 2012 at 03:45 PM
I've got the same fun little issue :) I'll post here if I solve it.
I solved it for now, but I don't know why it works. ^^
But try this: Extend the new Nav$$anonymous$$esh to the position where your player position ends in the last scene.
I think the problem is, that the second scene is loaded, then the Nav$$anonymous$$esh checks if there is a player positioned on it and then your new player position is set to the new position on the Nav$$anonymous$$esh. But when the last step happens it's already to late, Unity thinks your player is not positioned correctly.
Try it and let us know if it is in fact the problem. :-)
You are correct in the load order issue :) Hey Unity!! how about some way to override all this and manually set a navmesh :)
Answer by diekeure · Apr 23, 2013 at 06:32 AM
I have the same issue, but it's not possible for me to extend the navmesh... Any other possible solutions?
Answer by Homeship · Jun 17, 2018 at 08:23 AM
[Solution for your problem is here][1] [1]: https://docs.unity3d.com/540/Documentation/ScriptReference/NavMeshAgent.Warp.html
But I'm still fighting with NavMesh. 1) I 've baked NavMesh 2) I've active NavMeshAgent 3) Rigidbody is kinematic 4) GameObject with NavMeshAgent is placed in design-time and doesn't use any versions of transform.position =...
Still have a ""SetDestination" can only be called on an active agent..." error ((
Your answer
Follow this Question
Related Questions
NavMeshAgent Rotate With Model 0 Answers
NavMeshAgent don't move 0 Answers
CalculatePath often returns wrong results 0 Answers
Player's last location as a Transform 1 Answer
Unity pathfinding - Comparing 2 paths? 2 Answers