Bake_navigation_polygon() makes whole NavigationRegion2D disappear

Godot 4.4

Trying to get the very basics of navigation meshes to work.

var TempNavMesh = NavigationPolygon.new()
	var Vertices = PackedVector2Array([Vector2(0,0), Vector2(WorldWidth*32,0), Vector2(WorldWidth*32,WorldHeight*32), Vector2(0,WorldHeight*32)])
	TempNavMesh.vertices = Vertices
	var TempNavMeshIndices = PackedInt32Array([0,1,2,3])
	TempNavMesh.add_polygon(TempNavMeshIndices)
	$NavigationRegion2D.navigation_polygon = TempNavMesh

This works; creates a big mesh across the whole world.

var NewPolygon = Polygon2D.new()
	$NavigationRegion2D.add_child(NewPolygon)
	Vertices = PackedVector2Array([Vector2(5000,5000), Vector2(10000,5000), Vector2(10000,10000), Vector2(5000,10000)])
	NewPolygon.polygon = Vertices
	$NavigationRegion2D.bake_navigation_polygon()

Adding this block makes the whole region disappear. Just trying to create a square hole in the middle of the mesh.

Removing the whole second block except ‘$NavigationRegion2D.bake_navigation_polygon()’ gives the same result. bake_navigation_polygon() seems to make the entire mesh disappear.

For some reason everything works fine outside of scripts.


The two tiles with a physics layer painted on are removed from the mesh when I click ‘Bake NavigationPolygon’.

Just trying to figure out why it works in the main editor but not with a script.

I’m having the exact same problem right now. Did you ever find a solution?

I need to rebake my NavigationPolygon’s at runtime when i add or remove collision, so I can’t just rely on the editor version working.

Edit: for any who have gone down the same path as me, I have found out why it wasn’t working on my end.

I was using a lot of chunk based navigation, as per the Godot 2D Demo. When you bake a NavigationPolygon from parsed source data using NavigationServer2D.bake_from_source_geometry_data() you must set a bounding ‘traversible_outline’ in the source_geometry. This does what you’d expect it to do, and outlines an area that the navigation will look for collisions inside of.

You must also do this when baking a NavigationPolygon with NavigationRegion2d.bake_navigation_polygon()
The traversible outline for a NavigationPolygon is added using NavigationPolygon.add_outline()
The method’s documentation doesn’t clarify that this method is for adding a bounding/traversible outline, nor does the Using Navigation Meshes tutorial, so I was under the impression it was an outline of a collision polygon. It does however mention that at the very beginning of the NavigationPolygon documentation.