I am struggling with my NavMesh Agents computing an invalid path while there is obvisously no reasons. The problem occurs from time to time when they are already moving with an initial valid path.
On the above image, the destination is the cone on the top left corner. (Don't mind the NavMeshAgent's direction arrow, I tried to move the agent by hand so as to try to "unlock" him)
Checked the destination is on the NavMesh
public Vector3 GetCharacterPositionOnNavMesh( Vector3 position )
{
NavMeshHit hit;
bool positionFound = NavMesh.SamplePosition( position, out hit, 500, NavMesh.AllAreas );
if ( !positionFound )
Debug.LogWarning( "No valid position found !" );
return positionFound ? hit.position : position;
}
Checked the area mask of my agents to make sure they can find a path to the destination despite the various areas of the NavMesh
Checking almost each frame if the agent's path is invalid. If so, compute a new one using CalculatePath
or SetDestination
. Sometimes, it works, sometimes not.
protected virtual void Update()
{
if ( !Running || !agent.enabled || !agent.isOnNavMesh )
return;
if ( !agent.pathPending && agent.path.status == NavMeshPathStatus.PathInvalid && Time.frameCount % 2 == 0 )
{
NavMeshPath path = new NavMeshPath();
agent.CalculatePath( CharactersManager.Instance.GetCharacterPositionOnNavMesh( finalDestination ), path );
agent.SetPath( path );
}
}
Disabling all my NavMeshObstacle on the entire scene (My agents don't have any NavMeshObstacle on them nor on their children)
Adding more steps between the initial position and final destination
Disabled the AutoRepath property of the agent
Computing the path, storing all the corners and setting the destination of my agent one corner at a time using a similar method to this one
Note : When another agent pushes my first agent, the latter seems to wake up and find its path.
The NavMesh Agent component helps characters to avoid each other, move around the scene toward a common goal, or any other type of scenario involving spatial reasoning or pathfinding. Once a NavMesh has been baked for the level, it is time to create a character which can navigate the scene.
The NavMesh Surface component represents the walkable area for a specific NavMesh Agent type, and defines a part of the Scene where a NavMesh should be built. It is not in the Unity standard install; see documentation on high-level NavMesh building components for information on how to access it.
A navigation mesh, or navmesh, is an abstract data structure used in artificial intelligence applications to aid agents in pathfinding through complicated spaces. This approach has been known since at least the mid-1980s in robotics, where it has been called a meadow map, and was popularized in video game AI in 2000.
I had the Same issue Sometime ago where my agent just keeps deteriorating form the main path as if it getting new information on the move,
Then i checked about it and get to know that it updates its path on the move always checking for new shortest distance to go through as you said that you have disable the auto Path property i did the same but no help.
Then i came up with the idea to Get the Points on which my agent initially starts moving in a list and draw my own path to move my Agent on You can get the points from this and after that u have to smoothly translate your player\agent in on those points as it will be the shortest path.
But last but not least obstacle avoidance can be hard to overcome
if you find this help full give it shot and tell how it goes. its just what i have did in my case thought sharing it would be helpful.
Good Luck Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With