- Home /
Other old
"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
Answer by chrwoizi · Nov 11, 2016 at 08:31 AM
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.
Thank you very much, you have the correct answer, I just got the reference to the navmesh agent component and I used warp ( spown Location) and it solved my problem
I love when people like you try to solve the others problems. Thank you so much!!!
Please, someone, give him infinite points, I don't have nor one point.
Hi @chrwoizi where in code should the Nav$$anonymous$$eshAgent.Warp be called? Can I call it in start? In my scene I enable and disable rooms. So once the room is enabled it gives me this error
Answer by rasoulcarrera · Jan 18, 2014 at 11:27 AM
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
Just in bake tab of navigation click the bottom button that says Bake
Thanks rasoulcarrera, it works fine for me !
Thank you so much that worked great for me... u saved my life u have no idea
Answer by sandbaydev · Apr 10, 2018 at 04:45 PM
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: https://issuetracker.unity3d.com/issues/custom-navmesh-agent-type-causes-an-error-failed-to-create-agent-in-the-console
Answer by HappyLife · Jul 05, 2015 at 06:57 AM
There‘s a possibility that the value of Agent Radius or Agent Height was set too small to not make Agent move;
Answer by Nexonity · Aug 04, 2013 at 12:56 PM
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.
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
NavMeshAgent not fully reaching destination, thus it won't delete itself when it gets there 1 Answer
Question on Setting/Building Navmesh / Navmesh Agent Path 0 Answers
How to add variables to Components (Nav Mesh Agent)? 0 Answers