Unity “Failed to create agent because it is not close enough to the NavMesh” warning and resulting problems

What this error means is: the node where the NavMeshAgent is located is not placed on the pathfinding grid.

From the most basic understanding, it means that your character or an agent is not on the navigation terrain.

The most important thing is: the resulting error:

"SetDestination" can only be called on an active agent that has been placed on a NavMesh.

The character cannot move.

I have been looking for the problem for a long time. I searched on Baidu for four or five hours and found many solutions on the Internet, including but not limited to:

  1. Since the character is generated by Instantiate, it is not on the navigation mesh at the beginning, so you need to use something like NavMeshAgent.Warp(transform) to reset the position instead of transform.position to initialize the position.

  1. Different characters overlap and obstacle detection is abnormal. As long as you change the Radius to 0 or turn off Obstacle Avoidance, the characters can overlap and move.

  1. Or repeatedly activate the activation state of the Nav Mesh Agent component on the character.

  1. Some people have basic questions:

1>. The Navgation static tag of the object is not set.

2.> No baked nav mesh.

3.> The pathfinding object itself does not have a navigation component set up.

I had no problems with these, until I searched Bing for answers to this question from some foreign developers the next day.

I copied some machine translation methods:

1: Place the terrain at the origin 0, 0, 0

2: Put the script on the top: one is to put using unityEngineAI on the top, and the other is to try putting the C# script on the NavMeshAgent script.

3: First activate the NavMeshAgent script on the agent character, and then generate the network itself (this is subject to discussion)

4: Check whether the error reported is too far or too close, and raise or lower the terrain.

5: The proportion of the agent needs to be looked at. The proportion of the scene is too large. The rotation radius and height values ​​need to be adjusted appropriately.

6: Some say that the collider on the agent will be affected. Try to uncheck it or move it to another place.

To be honest, none of them solved my problem. I just followed the tutorial and made a simple navigation.

Until I saw a foreign brother said something:

Don't forget to check the Agent Type, since I had "New Agent" in my Agent, changing it to Humanoid helped me.

Just because I tried adding a new agent, and the character used this new agent, I even forgot that a new agent was added at that time. I just read in the book that there is such a function.

Solution:

Change the agent name back to Humanoid

Although this will result in only one proxy mode being selected, no error is reported.

I just learned this, and I don’t know why adding it doesn’t work. What if I want to add a different proxy mode ? If anyone knows about this situation, please leave a message

Guess you like

Origin blog.csdn.net/liyangufo/article/details/129629830