Search Unity

NavMesh check if changed due to obstacles added

Discussion in 'Navigation' started by Shadowphax, Aug 11, 2015.

  1. Shadowphax

    Shadowphax

    Joined:
    Jul 26, 2013
    Posts:
    8
    Hey guys

    I have the following problem. I have a NavMesh which works fine. My game allowed the player to add "Tower" which are also NavMeshObstacles. The problem I have is that I have to recalculate the path when a tower is placed. This is fine but I have noticed that the paths go stale AFTER the recalculation completes. So what it looks like to me is this:
    1) Place tower
    2) Request recalculate
    3) The Navmesh now finishes the carving calculations.
    4) The recalculation completes.
    5) The path is stale and agents don't move.

    Currently I'm working around this by waiting 1 second after placing a new obstacle but this is obviously horrible.

    Is there a better way to check if the NavMesh is completely up to date? I.e. no carving obstacles waiting to be taken into account? I've tried simply checking that the relevant scripts and components are active in the hierarchy but this doesn't help.

    The alternative I'm considering is having an agent somewhere that is always active but with a speed of zero. That way I can check the isPathStale property. But that also seems like a hack.