Visible navigation debug option not working for manually created navmesh

Godot Version

v4.2.2-stable_mono_win64

Question

Hi, I don’t use SceneTree/Nodes (except for entry point C# script) and do everything using server apis (so there is no navigation/navmesh related node at any point).

Currently, I only have some simple navmesh generation for testing (basically hardcoded Vertex3 array just like in the docs - Using navigation meshes — Godot Engine).

I can see that map, region, and polygons are registered correctly in the debug monitors, navigation and pathfinding are working as expected in game, but the “visible navigation” menu option doesn’t seem to do anything and I can’t see the navmesh in playmode.

Acording to #61625 - Add NavigationMesh debug when navmesh is added later through scripts this should work fine, but it seems it isn’t, at least not in my case when navmesh is generated though script from the ground up / without any nodes.

The debug render is specific to the nodes and doesn’t exist on the servers (currently), so this is expected

The linked issue was specifically for nodes not server based ones

This should probably be documented though

Thanks. Makes sense, although it’s still a bummer. Working on navmesh generation without this is going to be painful.

Is there any way to get out the “true” navmesh Godot is using so I can render it myself? If not, then - i guess - my best bet is to mock everything up just like in the game and use nodes while working on this.

This should probably be documented though

Yes, this wasn’t immediately obvious after reading the docs.

The true mesh in what sense? What’s missing from the data available with the polygons and vertices? As compared to the rendered form

I’ve been thinking for my particular case it would be easier to generate mesh using quads, and it works fine from my basic testing, but i’m not sure if Godot is for example triangulating and/or doing other optimisations to this mesh behind the scenes.

I miss a function to get the polygons of the regions :slight_smile:

I needed to save all the navigation polygons into an array in order to draw them all

	for nav_polygon in nav_polygons:
		var navigation_mesh : NavigationMesh = nav_polygon.get_navigation_mesh()
		var vertices : PackedVector3Array = navigation_mesh.get_vertices()
		
		for i0 in range(0, navigation_mesh.get_polygon_count() ):
			var raw_polygon : PackedInt32Array = navigation_mesh.get_polygon( i0 )
			var vs : Vector3 = vertices[ raw_polygon[ 0 ] ]
			var ps : Vector2 = Vector2( vs.x, vs.z )
			var p0 : Vector2 = ps
			for i1 in range( 1, raw_polygon.size() ):
				var v1 : Vector3 = vertices[ raw_polygon[ i1 ] ]
				var p1 : Vector2 = Vector2( v1.x, v1.z )
				draw_line( p0, p1, Color.GREEN, 1.0, true )
				p0 = p1
			draw_line( p0, ps, Color.GREEN, 1.0, true )
		
		for v in vertices:
			draw_circle( Vector2( v.x, v.z ), 4.0, Color.BLACK )

You mean get all the polygons at once? You can get the polygons with get_polygon :wink:

Found a simpler way. It works for my simple case, anyway. YMV.

I’ve added a NavigationRegion3D node to my scene (just for the visual navigation option to work), and then in the navmesh generation code:

        var mesh = new NavigationMesh();
        Region = NavigationServer3D.RegionCreate();

        NavigationServer3D.MapSetActive(Map, true);
        NavigationServer3D.RegionSetMap(Region, Map);
        NavigationServer3D.RegionSetEnabled(Region, true);

        mesh.Vertices = [
            new Vector3(0, 0, 24),
            new Vector3(24, 0, 24),
            new Vector3(24, 0, 0),
            new Vector3(0, 0, 0),
        ];

        mesh.AddPolygon([0, 1, 2, 3]);
        NavigationServer3D.RegionSetNavigationMesh(Region, mesh);

        // regionNode is the NavigationRegion3D node instance
        regionNode.NavigationMesh = mesh;

This somehow glues the navmesh debug rendering code and seems to work just fine, probably thanks to #61625

@athousandships anyway, thanks for pointing me in the right direction!
@txesmi maybe this could solve your problem too

:slight_smile:

1 Like

I’m sorry, I meant get polygons by the navigation server but did not want to mess the topic. Just wanted to show that the polygons can be drawn for debug.
I miss a lot of things in the server indeed.

@plunntic thanks!

1 Like

Currently the navigation debug visuals are all node based so if you use NavigationServer objects without nodes you need to create your own debug for them. This is documented in the navigation debug section of the documentation.

There are plans to change this and a proposal open for it here Make NavigationServer handle all navigation debug visuals · Issue #7208 · godotengine/godot-proposals · GitHub but I did not make much progress on it due to RenderingServer shenanigans at that time that I did run into.

That there is no debug without nodes is not exlusive to navigation, you also see no e.g. physics debug if you only use server objects. The exception is rendering because rendering has all its visual data internally available. There are actually API problems with e.g. camera and viewport stuff that make it hard for other servers to communicate with the rendering for debug.

Thanks for more in-depth explanation!

I’ve subscribed to #7208 and for the time being, I’m going to postpone my project because after evaluation it seems currently there’s just too much engine level functionality I’d have to reinvent & roll custom implementation for, for my simple project.

At least from what I’ve found:

  • there’s no easy way to animate meshes when using rendering server
  • there’s no easy way to create navigation mesh at runtime when using navigation server

Gonna try some other, more traditional / node-based ideas :smile: