What would cause a NavMesh agent to compute an invalid path ?

Hello everyone,

###Description of the problem

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.

Agent can't find his way

On the above image, the destination is the cone on the top left corner.

  • When instantiated, I ask my agents to compute their path to a given destination point on the NavMesh (I use NavMesh.SamplePosition to make sure the destination point is on the NavMesh). Everything works fine. The agent find his way and starts to move towards his target
  • But, during is journey, suddendly, he loses himself while the NavMesh has not changed since the first step. I haven’t asked him anything, no new computation of a new path.

###Solutions tested

  1. 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;
  2. 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

  3. 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 )
        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 );
  4. Disabling all my NavMeshObstacle on the entire scene (My agents don’t have any NavMeshObstacle on them nor on their children)

  5. Adding more steps between the initial position and final destination

  6. Disabled the AutoRepath property of the agent

  7. 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

Yeah, any NavMesh Calculation errors I have is because I had an OLD map_bake and I simply needed to re-bake the scene.