Search Unity

How to enable/disable parts of the NavMesh at runtime

Discussion in 'Navigation' started by Thrazamund, Jun 27, 2022.

  1. Thrazamund

    Thrazamund

    Joined:
    Apr 14, 2017
    Posts:
    36
    How do you enable or disable parts of the Navmesh at runtime without rebaking the entire NavMesh? I've been searching high and low but can't find anyone talking about this. I feel like it must be one of the most common use cases though and so maybe I'm missing something very obvious.


    Example: Player enters a combat arena and begins to fight skeleton NavMesh agents. Inside the arena is a bunch of boxes that necromancers will pop out of after you kill the skeletons. You need the ground under the necromancer boxes to be enabled as walkable only after the player kills the skeletons. If you just make the boxes NavMesh obstacle the skeletons in the arena will not intelligently navigate around them. Surely, there must be a way to just enable those ground tiles under the boxes at the right time instead of the performance hit of rebaking the NavMesh of the whole level at runtime.
     
    devbot_amata likes this.
  2. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    What you need are NavMeshObstacles with the "carve" option. Add this component to any gameobject (such as your box) that needs to "cut out" a piece of the mesh at runtime for far less cost then rebaking it.