Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NavMeshPathStatus is always PathComplete

Discussion in 'Navigation' started by Bytewizards-SE, Apr 7, 2016.

  1. Bytewizards-SE

    Bytewizards-SE

    Joined:
    Aug 24, 2015
    Posts:
    14
    Consider the following Code:

    Code (CSharp):
    1.  
    2. NavMeshPath navMeshPath = new NavMeshPath();
    3. if (navMeshAgent.CalculatePath(navMeshTarget, navMeshPath))
    4. {
    5.         switch (navMeshPath.status)
    6.         {
    7.             case NavMeshPathStatus.PathComplete:
    8.                 Debug.Log("Complete");
    9.                 break;
    10.  
    11.             case NavMeshPathStatus.PathPartial:
    12.                 Debug.Log("Partial");
    13.                 break;
    14.  
    15.             case NavMeshPathStatus.PathInvalid:
    16.                 Debug.Log("Invalid");
    17.                 break;
    18.         }
    19. }
    20.  
    Even though I set the navMeshTarget vector outside a baked navmesh or inside a NavMeshObstacle, my switch-statement always land on NavMeshPathStatus.PathComplete.

    IIRC, I had a different behaviour prior to the latest update...?
     
  2. JackofTraes

    JackofTraes

    Joined:
    May 28, 2014
    Posts:
    10
    Hello, this is a little bit late but, I ran into the same problem. After a bit of experimentation, it seems that navMeshPathStatus is for a completely different purpose than it suggests (most likely to do with the NavMesh itself and not the NavMeshAgent's path).

    What you are trying to do is find out if the NavMeshAgent has reached its destination. For that, try something like this:

    Code (CSharp):
    1.         if (!NavMeshAgent.pathPending && !NavMeshAgent.hasPath) {
    2.             Debug.Log ("I have reached my destination!");
    3.             // Code that you want to execute when this event occurs.
    4.         }
    Basically, this asks if the agent has a path or is in the process of calculating one. When the agent is at its current destination, both of these conditions are false and this is the exact moment that you want to capture. I hope this helps you and anyone else that has this issue.
     
    Vladislav0, Vectrex, Rim32 and 12 others like this.