Search Unity

NavMesh and NavMeshObstacles problem

Discussion in 'Navigation' started by mpiastowski, Sep 22, 2016.

  1. mpiastowski

    mpiastowski

    Joined:
    Jun 16, 2015
    Posts:
    6
    Hi,

    I use Unity NavMesh and I have a problem. I searched forum with no success, so I decided to create new post.
    My scene is random generated, so I use NavMeshObstacles.
    Usually everything goes fine, but sometimes my agent goes crazy: goes forward and backward repeatedly, or tries to go through obstacles. It's difficult to describe, so I post a video:

    NavMesh seems ok, but agent path does not.
    I generate obstacles and call NavMeshAgent.SetDestination in the same time.

    My obstacles settings:
    carve = true
    carve only stationary = false (tried true as well)

    My NavMeshAgent settings:
    Auto Repath=true
    Obstacle Avoidance Type = None / High quality (tried both)

    My Unity version: 5.4.1f1 (Windows/Android)

    What I already tried (with no success):
    - I tried different options of NavMeshObstacle and NavMeshAgent
    - I tried smaller NavMesh voxel size
    - I called NavMeshAgent.SetDestination with 2 seconds delay

    All suggestions are welcome, because I have no more ideas.
     
  2. mpiastowski

    mpiastowski

    Joined:
    Jun 16, 2015
    Posts:
    6
    I reported this as a bug 834415
     
  3. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    Just an idea but have you made sure you dont have something wierd going on with your layers.. Dynamic objects as static..etc..
     
  4. mpiastowski

    mpiastowski

    Joined:
    Jun 16, 2015
    Posts:
    6
    Thank you for your response.

    The only static object is the plane.
    I defined more NavMesh layers in my project, but I use only "walkable".
    Maybe I messed something up, but I really don't know what.
     
  5. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219
    Hi @mpiastowski have you find a solution for this? is happenning to me and also a couple of people over internet are experiencing the same issues, no one got a clear answer and for what I can see, unity devs are looking away and don't answer because probably this is a bug that cannot be addressed without completely redoing how the pathfinding works, I feels like the pathfinding solution under the hood is quite poor to handle this kind of scenarios and the agents goes crazy trying to repath or something, going back and forth in the same place like don't knowing what the hell to do.

    the problem seems to depend on voxel size, tile size and complexity of the generated mesh, I can assume it's related on how the polygon information and some extra/interpolation of positions is calculated, from my poor knowledge on the subject.

    thanks for any answers on this!
     
  6. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    This particular one is fixed from 2017.1 - a backport to 5.6 is being considered.
     
  7. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219
    hi @Jakob_Unity thanks for the clarification, I ended up moving to A* Pathfinding project pro, now that you said that, maybe I reconsider going back to unity's own navmesh system.

    only one problem left though, can you teach me if there is any way to do something similar to what A* offers with one of their methods? this is what I need, is for a TD game:

    --------------------------------------------------------------------------------------
    Check for blocking placements
    A common thing in tower defence games is to make sure that the towers the player places does not block the path between the spawn points and the goal. This might seem hard to do, but luckily there is an API for that.

    The Pathfinding.GraphUpdateUtilities.UpdateGraphsNoBlock method can be used to first check if a given graph update object will cause the path between two or more points to become blocked. This is however slower than a normal graph update so you probably don't want to use it too often.

    For example when a player in a tower defence game places a tower, you could instantiate it, then call the UpdateGraphsNoBlock method to check if the newly placed tower will block the path. If it did then remove the tower immediately and notify the player that the choosen position was not valid. You can pass a list of nodes to the UpdateGraphsNoBlock method so you could for example make sure that not only is the path from the start to the goal not blocked, but also that all units can still reach the goal (if it is possible to place towers when enemies are walking around).

    Code (CSharp):
    1. var guo = new GraphUpdateObject (tower.GetComponent<Collider>.bounds);
    2. var spawnPointNode = AstarPath.active.GetNearest (spawnPoint.position).node;
    3. var goalNode = AstarPath.active.GetNearest (goalNode.position).node;
    4. if (GraphUpdateUtilities.UpdateGraphsNoBlock (guo, spawnPointNode, goalNode, false)) {
    5.     // Valid tower position
    6.     // Since the last parameter (which is called "alwaysRevert") in the method call was false
    7.     // The graph is now updated and the game can just continue
    8. } else {
    9.     // Invalid tower position. It blocks the path between the spawn point and the goal
    10.     // The effect on the graph has been reverted
    11.     Destroy (tower);
    12. }
    13.  
    -----------------------------------------------------------------------------------------

    https://arongranberg.com/astar/docs/graph-updates.php#blocking



    Thanks for any answer on this, is another thing that is keeping me from being able to use unity navmesh into my TD game, cheers!
     
  8. PerunCreative

    PerunCreative

    Joined:
    Nov 2, 2015
    Posts:
    113
    Hi,

    any news on 5.6 fix? This bug is a really bad for our game.
     
  9. true_warlock

    true_warlock

    Joined:
    Aug 2, 2019
    Posts:
    60
    So all current LTS versions of the editor have this Known issue... maybe they need to roll everything back to 2018.4.0f1 and start over cause all these broken bells and whistles and now the annoyance of "Repant" notices every time you open a tab is over the top annoying.