godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.47k stars 21.07k forks source link

Unexpected Error when using Navigation Mesh with Grid Map #72188

Closed wkirby closed 1 year ago

wkirby commented 1 year ago

Godot version

v4.0.beta16.mono.official [518b9e580]

System information

macOS Ventura 13.1, M1 Max

Issue description

Attempting to integrate Navigation Mesh and Grid map results in the following error:

E 0:00:02:0329   sync: Attempted to merge a navigation mesh triangle edge with another already-merged edge. This happens when the current `cell_size` is different from the one used to generate the navigation mesh. This will cause navigation problems.
  <C++ Source>   modules/navigation/nav_map.cpp:691 @ sync()

This results in nav agents being unable to navigate the resulting nav region.

Steps to reproduce

Creating the Mesh Library

Using the Mesh Library

Minimal reproduction project

Navigation Test.zip

wkirby commented 1 year ago

For added context, I may be misunderstanding the expected interactions between the 3D navigation system and grid maps. My desired functionality is to make some meshes in my gridmap navigable, and some non-navigable. My understanding from the existing documentation is that if I add a nav mesh to some mesh instances, and tick the bake_navigation setting in the Grid Map, that the Grid Map will produce a navigation region from the nav meshes.

Relevant documentation from GridMap:

If true, this GridMap creates a navigation region for each cell that uses a mesh_library item with a navigation mesh. The created navigation region will use the navigation layers bitmask assigned to the MeshLibrary's item.

wkirby commented 1 year ago

Still happening on v4.0.beta17.mono.official [c40020513]

smix8 commented 1 year ago

The reason why this does not work for you is cause you don't use a valid NavigationMesh.

box_navmesh

If you enable navigation debug in Editor->Debug->Visible Navigation you will see quickly what is wrong. Seems like you just copied over your visual mesh to the navigation mesh slot. This does not work as a navigation mesh can not have a volume, it needs to have flat surfaces.

The GridMap does no baking, it reads the already baked navigation meshes from the MeshLibrary and the MeshLibrary expects already baked NavigationMesh resources when you set cell items. The bake_navigation option on the GridMap creates navigation regions for each cell with a MeshLibrary navigation mesh but it does not baking of the navigation meshes from any source geometry. That step needs to happen already before and when you create your MeshLibrary.

What you can do is use a NavigatioRegion3D, add a NavigationMesh resource and set the agent_radius to zero, add a child MeshInstance3D and add you visual mesh inside. Then bake your NavigationMesh, store it on disk and load it in your MeshLibrary as the cell navigation mesh.