Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How to determine any NavMesh modification ?

Discussion in 'Navigation' started by Samoustique, Feb 12, 2016.

  1. Samoustique


    Feb 12, 2016
    Hi everybody,

    I am trying to program a "Tower Defense" game.
    My battlefield is a plan where I put a NavMesh. The mobs (ennemies) appear on the left and try to go until the very right. The player builds tower to kill them on their way.

    When the player selects a type of tower he wants to build, I color the different "squares" of the battlefield where he can build it. Green if OK, red otherwise. The player cannot build if it blocks the way of course.

    To measure that, I instantiate a "fake" Nav Mesh Obstacle on a square, then I recalculate the path from the departure until the arrival. I apply the good color on the square according to the resulting status. Then, I destroy the fake obstacle.

    Here is my problem :
    After instantiating my fake NavMeshObstacle, I must wait a few amount of time before calculating. If I don't, the NavMesh won't be impacted by the new obstacle, hence the calculation will be wrong.
    Is there any possibility to determine when the NavMesh have been changed by a new Obstacle ?


  2. pixxelbob


    Aug 26, 2014
    You may need to wait for the next frame before re-calculating.
    A navmesh agent will automatically path around an obstacle, so you really shouldn't need to do this.