How to update the navigation map?

Godot Version



I have a NavigationObstacle3D, the navigation map has baked its original position and ignores that it has changed position.
I have CSGBox3D, the navigation map also bakes the first position and ignores subsequent ones.
I have NavigationAgent3D and they ignore agents on their path and the first two points that have moved.
How can I update the navigation map to prevent this mess from happening?

You change a navigation map by changing its regions and the regions navigation mesh. Either rebake the navigation mesh on a region or change the navigation mesh resource in script and update the region with the changed resource.

A NavigationObstacle3D has nothing to do with pathfinding. It is for avoidance only in Godot 4.2.2 and can not even be baked to a navigation mesh, that was only added recently in Godot 4.3 beta as a new property.

But how exactly should I change it during the game? What script, command, function should I use?
Moreover, judging by this article, NavigationObstacle may well influence in real time whether an NavigationAgent can pass through. True, there are not enough details in the article.

What is important is to know is that the pathfinding is based entirely on the navigation mesh surface. This means if you want to change anything about the path, you change the navigation mesh.

You do that by either (re)baking it with the NavigationRegion3D.bake_navigation_mesh() function at runtime or by using the NavigationServer3D functions to parse source geometry and bake navigation mesh.

You can find script examples for that in the documentation, e.g. the navigation mesh doc here Using navigation meshes — Godot Engine (latest) documentation in English

The avoidance has nothing to do with how the path turns out because what the avoidance does is that it changes the provided velocity of an agent, it does never change the path, it does not even know that a path or navigation mesh exists.

Because the NavigationObstacle in Godot 4.2.2 is avoidance only it is technically impossible that it can influence the path, it can only affect the agent velocity. If there is a path point directly below the obstacle that the agent can not reach it might as well get stuck on it.

That old article has an “outdated” warning for a reason as it is very staged, does not show any of those known problems, and never really worked well like that in practice.

1 Like