Looking for hints about 2D navigation mesh structure

Godot Version



Hello community,
I am almost new to Godot and have been studying how to use the navigation server functions and its associated nodes. I have managed to build, not without effort, the necessary structures to create and register the meshes dynamically both with the server and creating nodes by code.

My goal is to create a base building game and build the navigation grid dynamically in reference to the buildings and other things that the player places in the scenario and move the npcs from one place to another.

I have doubts about which way to choose in the development of the base structure of the meshes. I can’t find much information about it. I understand that I can divide the scenario into different maps and thus save the path finder some effort by using key points to switch from one map to another, although I don’t know what impact it has to be changing the agents continuously from map to map.

I also understand that I can bake the meshes of a map into multiple regions connected by their edges or links and be able to turn them on and off at convenience or set the appropriate masks on the agents, although I don’t know what impact this type of connections has with respect to using a single mesh on the entire map. As well as whether the massive use of regions has a significant impact.

Any advice on this?

Thanks in advance

The navigation documentation has script examples how to create basic navigation meshes in code.

A navigation mesh structure is just that of a two-dimensional mesh with no overlap or self-intersection. The mesh consists of an array of vertices and an array of polygons. Each polygons is an array of indices for the vertices array. The polygons do not need to be triangles, they can be convex.

The navigation regions are the partition units of the navigation mesh system. Each region can hold and update its own navigation mesh. If your entire navigation map never changes at runtime you can use just one region and one navigation mesh, it wouldn’t matter. As soon as you do runtime changes to the navigation mesh you want more regions so you do not need to change the entire navigation map all the time in full.

Navigation meshes are merged together by their edges. If two unique edges overlap they are merged together. If a third edge tries to do that on the same positions it is a logical error.

If you use a server created agent the only point to keep it on a map is for avoidance simulation. For the pathfinding you dont need a map assigned to the agent, you can query any map you want with the map_get_path() function. E.g. you can have a hierarchy with multiple maps at different navigation mesh detail level to speed up the pathfinding.

1 Like

Thank you very much!

As I understand you, I can use many regions without a significant impact on pathfinding with respect to using a single mesh, right?

I’m not really concerned about the time it might take for a mesh to generate in real time.