Search Unity

NavMesh - Getting pathComplete when destination not reachable

Discussion in 'Navigation' started by SentientSkull, Jan 16, 2019.

  1. SentientSkull

    SentientSkull

    Joined:
    Apr 26, 2013
    Posts:
    75
    I have a small test scene with simple areas that aren't connected. I have a NavMesh baked. I've got a character with a NavMeshAgent and I'm placing a target at random points within 10 units of the character, then using NavMesh.SamplePosition. If it passes that, I use SetDestination on the agent, then check pathStatus for PathComplete or PathPartial (I'm using PlayMaker, but these are the methods being used by the actions).

    The problem is that when the random target is placed on another area that's not connected to the area the agent is on (and even if there is a wall completely blocking the area), pathStatus is returning PathComplete, and the agent gets stuck trying to get to an unreachable area.

    From what I've read, using SetDestination causes the path to be calculated in a separate thread, so it's not available immediately. The PlayMaker action I'm using fires events (Path Complete Event, Path Partial Event) so I would think that would work. It waits for one of these events and then either moves towards the target or generates a new target if it can't be reached. It works fine if the target is on the same connected area, but breaks when on an unconnected area.

    Anyone know why it would return pathComplete when it's not possible for the agent to reach the destination?

    Edit: I forget to add that I had also tried it with NavMesh.CalculatePath, then using Agent.SetPath and checking path status and that does seem to work. But I would like to get it working with SetDestination as above.

    NavMesh1.png NavMesh2.png NavMesh3.png
     
    Last edited: Jan 16, 2019
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    If I remember correctly the NavMeshAgent will, when given a target it cannot reach, actually set its destination to the furthest point on the path it can reach and use that as destination. Because of that you always get the Complete result.
    You can debug this perhaps by spawning a little cube on the Agent's destination after you've set it?
     
  3. SentientSkull

    SentientSkull

    Joined:
    Apr 26, 2013
    Posts:
    75
    NavMesh4.png Ok, I added a cube and I place it at the current agent destination after checking path status. It's the same as the target destination, so I really don't understand what's going on here.

    NavMesh5.png
     
    Last edited: Jan 17, 2019
  4. SentientSkull

    SentientSkull

    Joined:
    Apr 26, 2013
    Posts:
    75
    I think I have it working now. The 'Get Agent Path Status' action wasn't waiting for pathPending == false (I assumed it was). I added a state that runs until pathPending becomes false before it tries to check Path Status.

    While trying to solve this I found a good article that shows how the nav mesh system behaves in various situations that isn't always obvious. It might be helpful to others with similar problems.
    Taming Unity's Navigation System - Assumption Testing Part 1
    http://unitytipsandtricks.blogspot.com/2015/10/taming-unitys-navigation-system.html
     
    Seith likes this.
  5. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    This hasn't helped me, I've still been 38m away from a destination and pathPending=false and pathStatus=PathComplete.
    It looks like I'll have to go back to checking just distance to target again with some sort of other additional AI

    I used NavMeshAgent on a large project 2 years ago and it was a mess for this sort of thing, it seems it's no better in 2020.2
     
  6. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    133
    It's still a complete mess year of our lord and savior 2022
     
  7. Kas_

    Kas_

    Joined:
    Dec 27, 2017
    Posts:
    72
    Still an issue
     
    Salmanovicius likes this.
  8. TKDHayk

    TKDHayk

    Joined:
    Dec 22, 2015
    Posts:
    131
    is there an alternate way to check if the target is reachable? this method is broken. Shame on Unity for not improving their core engine features that thousands of devs rely on