What is the proper way to modify navigation mesh during the game?

Godot Version

4.5 Mono

Question

In NavigationMeshSourceGeometryData2D, there are add_projected_obstruction and add_obstruction_outline for adding obstructions, and they both takes PackedVector2Array as input. What are the difference between them?
To my understanding, when you procedurally generate Source Geometry to bake nav mesh into the NavigationPolygon, you use add_traversable_outline to create walkable areas, and use add_obstruction_outline to cut holes in these areas. During game running, when you need to make changes to nav mesh, e.g. a building(obstacle) is placed or a bridge on water(unwalkable turns to walkable), you should manipulate SourceGeometry and bake again.
But if there is already an obstacle added byadd_obstruction_outline in original Source Geometry, can you directly add_traversable_outline of new walkable area that overlaps with existing obstacles and expect baking process handle them all?

Easiest way:

  1. Add all obstacles as children of the NavigationRegion3D node.
  2. Rebake the mesh when you add or remove one.

The projected_obstructions are the special geometry added by navmesh carving NavigationObstacles. I know projected does necessarily ring a bell in 2d for most people because everything is just flat planed in 2d anyway, but it has the shared naming with 3d here where the obstacles can not be transformed freely because they are 2-dimensional projected on a plane, hence the name.

Meanwhile the 2d obstruction_outlines are just the normal “collision” geometry parsed and used in a baking process to create normal “holes” in the navmesh. They are the outlines that get intersected with the traversable_outlines, while the projected_obstructions are handled in a later pass as a final surface cut.

So the order is basically:

  • traversable_outlines get merged as the navmesh surface
  • obstruction_outlines get merged and intersected with that traversable surface creating “holes” in that surface with agent radius offset.
  • project_obstructions carve obstacles cut into that final surface without agent offset.
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.