Search Unity

Rare instance where NaveMeshAgent doesn't move with a good path?

Discussion in 'Navigation' started by skowroshima, Jan 7, 2021.

  1. skowroshima

    skowroshima

    Joined:
    Oct 14, 2018
    Posts:
    75
    I've had rare instances where I will have a NavMeshAgent remain stationary after successfully calculating a path. In looking at the agent: pathPending == true, pathStatus == NavMeshPathStatus.PathComplete, isOnNavMesh == true, I've rendered the calculated path and it looks correct, everything looks good, just no velocity. While this rarely (seemly randomly) happens, I was able to create a save file for my game where the agent will always get stuck on it's first SetDestination.

    Any ideas on what is going on and what I could do to troubleshoot this?

    I've come up with a garbage workaround where if I see they have a path and they haven't moved in 5 seconds, I bump them. Most of the time the NavMeshAgent snaps back to the position it was at, but sometimes the bump will be enough to get them to continue on the path. I'm wondering if the fact it usually snaps back is a clue to what is going wrong...


    Garbage workaround:
    Code (CSharp):
    1. if (!mNavMeshAgent.pathPending && HasNotMovedInAWhileWithPath())
    2. {
    3.     NavMeshHit hit;
    4.     Vector3 bumpedPosition = transform.position + Quaternion.Euler(0, UnityEngine.Random.Range(0, 360f), 0) * Vector3.forward;
    5.     if (NavMesh.SamplePosition(bumpedPosition, out hit, Citizen.cMaxNavMeshRange, NavMesh.AllAreas))
    6.     {
    7.         transform.position = hit.position;
    8.         Debug.Log("mNavMeshAgent not moving with path... bumping - pathing status" + mNavMeshAgent.pathStatus + ", on mesh -" + mNavMeshAgent.isOnNavMesh);
    9.     }
    10. }
     
  2. nico_st_29

    nico_st_29

    Joined:
    Mar 14, 2020
    Posts:
    69
    Hello,

    I have a similar issue. For me it seems to be related to the number of agents in the scene at a given time.

    I've posted a video on the channel showing the issue (see the dwarves in the top-right at the end):