NavMesh Returns Impossible Paths

Started by Woeful 3 posts 61 views

Reply on sbox.game
  1. #1
    Woeful 273
    Hi!

    Has anyone experienced issues with NavMesh returning nonsensical paths after a while?(Can start happening after about 10 seconds of the game running, sometimes only after a minute or so. It might just be completely random, but I haven't had it happen right after the game starts).

    I have a testing object that runs around the scene using a generated path to a random point and once it reaches it a new point is chosen and next path generated. Note; I am not using the built in NavMesh - Agent helper component.

    It works fine for a bit, then randomly starts outputting paths which are not possible from the start position.

    (DebugOverlay: White is current position, orange is path lines/points, cyan is target. The semi-transparent dark parts in the middle are static, elevated wall obstacles.)
    image.png 495.43 KB
    Literally the first point in the generated path is on the other side of the NavMesh, quite close to the target, but straight through the walls and then some nonsensical routes away from the target, around the map and then back.

    This is the code I'm using, 
    private void GetNewTargetPath()
    {
      var randomPoint = Scene.NavMesh.GetRandomPoint();
      if ( !randomPoint.HasValue ) return;
      _targetPosition = randomPoint.Value;
      _path = Scene.NavMesh.GetSimplePath( WorldPosition, _targetPosition );
    }

    I can regenerate a bunch of paths, they usually start out fine, but after a while it's starts generating these broken ones.

    Here is a screenshot of the generated NavMesh too, looks fine to me.
    image.png 522.02 KB
    Settings are also quite normal.
    image.png 21.76 KB


    I've also tried setting the start point as the closest valid NavMesh position, same issue:
    private void GetNewTargetPosition()
    {
      var randomPoint = Scene.NavMesh.GetRandomPoint();
      if ( !randomPoint.HasValue ) return;
      _targetPosition = randomPoint.Value;
      var startPoint = Scene.NavMesh.GetClosestPoint( WorldPosition );
      if ( !startPoint.HasValue ) return;
      _path = Scene.NavMesh.GetSimplePath( startPoint.Value, _targetPosition );
    }

    I have a dirty workaround at the moment to get around this; I trace a ray from the first path point to the next, and see if anything is hit. If it did hit something it obviously generated an impossible path through a wall or something, so I discard that path and get a path to new random point.

    This might be important:
    When I *do* detect one of these impossible, broken paths and have to generate a new one, I have to move the target end point of GetSimplePath to somewhere completely different. If I try and select a new target end point *near* the original, using GetRandomPoint with a radius parameter (of about 30f), it will continue to fail, I need to completely abandon the target end point, and get a completely random new one somewhere else far in the map.

    Any help at all would be greatly appreciated.

    Sorry for the long post, wanted to get as much info of what I've done/tested in here.
  2. #2
    Braxen 🐟 190
    i find GetSimplePath to be extremely unreliable, it often doesn't work at all or generates different paths that a navmesh agent would walk itself
  3. #3
    Woeful Started this 273
    Is there any alternative?