Failed to create agent because it is not close enough to the NavMesh & "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
All the answers I found for the similar problems doesn't fix my headache :(
In my project what I'm trying to do is instantiate lots of worm based on a worm already in the world, and the worm has some simple AI so they can move randomly around. There is an object pooler to recycle the worms so they can be generated again in front of person, and whenever it is called again to be shown at the new position, it has a chance to popup those errors and warning (while some of them are just doing fine).
This is the simple object pool I've got:
private void Start()
{
items = new List<GameObject>();
//add all the objects to the worm mesh pool
for(int i = 0;i<amount; i++)
{
GameObject obj = Instantiate(itemSpawn);
obj.GetComponent<NavMeshAgent().Warp(itemSpawn.transform.position);
//deactive the object for the start
obj.SetActive(false);
items.Add(obj);
}
InvokeRepeating("Spawns", frequncy, frequncy);
}
void Spawns() //active the object from the worm pool
{
//get player position
pos = player.transform.position;
for (int i = 0; i < items.Count; i++)
{
if (!items[i].activeInHierarchy)
{
//generate a random position in front of the player on the plane
Vector3 position = new Vector3(Random.Range(-5F, 5F),
Random.Range(0.5F, 3.50F),
Random.Range(0.0F, 30.0F) + pos.z+0.5f);
items[i].transform.Rotate(0,(Random.Range(-90F, 90F)),0);
items[i].SetActive(true);
items[i].GetComponent<NavMeshAgent>().Warp(position);
break;
}
}
}
I tried to add download the navmesh component form https://github.com/Unity-Technologies/NavMeshComponents which helps me none. Also checked the position where the worms are generated, since I set the navmesh surface be really free, big and high, I don't think that this problem is caused by the agent not on surface. Changing on the prefab is also not helpful. Those worms are instantiated form the same gameobject which is already in the world, when the one triggered the problem it won't move as much as its own kind. These doesn't effect much on the game now, but keep getting these errors, I think it's better to be fixed. Hope someone could give me a hand on what is going on...
good day.
Can you post an image of the scene, whewre is the spawn position, the warp position, the navmesh area, how are the agents capsules, how is the mesh baked.
AS more info, more probability to get an answer
bye!
Thanks for replying! The instantiation is based on this gameobject:
The agent collider doesn's seem to match the mesh position as well:
The reply seems only allows two image each, so you will get several replying for this topic, sorry for that... I edited the spawner to make it spawn slower so I can see which has the problem and which doesn't. I find no difference between the data. This is a trouble maker worm:
Answer by tormentoarmagedoom · Jun 27, 2018 at 08:23 PM
Good day.
You are not warping coreectly, you forget to close the getcomponent, look what ypu have :D
obj.GetComponent<NavMeshAgent().Warp
so is not executing that line, so you are not warping it.
:D Byee
LOL I'm gonna try out, did this dumb mistake really bothered me for days. Thank you!
it's obj.GetComponent().Warp(position); In the code, and it doesn't effect on the functionalities. Also the problem doesn't happened when instantiation, it only happens sometime after the worm need to show up at the new position. Thanks anyway :(
Your answer
Follow this Question
Related Questions
NavMeshAgent isn't chasing the player 0 Answers
NavMeshLink don't work in correctly in certain area 0 Answers
navmesh agent not working after update to 2017.1 3 Answers
NavMeshSurface or NavMeshAgent agentTypeId can't be changed on runtime 0 Answers
How can I check the destination outside the navmesh? 1 Answer