Search Unity

Question Using Navigation to test if areas are reachable

Discussion in 'Navigation' started by AgentParsec, Feb 25, 2023.

  1. AgentParsec

    AgentParsec

    Joined:
    May 5, 2012
    Posts:
    403
    I built a random map generator for a game I'm working on but didn't make it easy to determine viable paths through calculation, so I'm trying to set it up so that I can check for reachable areas through NavMeshAgents instead. The NavMesh itself is generating properly (it starts as a blank square area, and every wall added counts as an 'obstacle' which carves holes in the NavMesh, and allows me to change their positions on the fly). I'm trying to find the best way to drop a NavMeshAgent in front of the entry door, give it another location (in front of the exit door), and check to see if it's able to reach that location; if it isn't, it will be forced to make modifications to the map to compensate.

    Originally, I just tried seeing if it could just calculate a path, but it didn't seem to work; it always returned a success even if it wasn't reachable. Then I tried setting a destination on the NavMeshAgent and waiting until it finished calculating the path, then checked it again, but it seems to return a positive result even if there's an obstruction; I believe this is because even if it can't reach the destination, it still tries to make it as close as possible, and thus is still "successful". In both cases, I'm making sure to wait the necessary frames to make sure everything updates properly.

    Am I making this too hard on myself? Is there an easier way to do this? Should I instead try to just figure out how to calculate the reachability of the exit manually without the use of NavMeshAgents?
     
  2. AgentParsec

    AgentParsec

    Joined:
    May 5, 2012
    Posts:
    403
    Nevermind, I figured it out. The test path wasn't working because I was testing for the wrong path type (PathInvalid instead of PathPartial). I changed it, and it's working now.