godotengine / godot

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

Baking navigation mesh with GDScript produces error messages #78576

Closed deezaster closed 1 year ago

deezaster commented 1 year ago

Godot version

4.1.beta3

System information

Godot v4.1.beta3 - macOS 13.2.1 - Vulkan (Forward+) - dedicated AMD Radeon Pro 580 - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz (8 Threads)

Issue description

When baking the mesh in GDScript after placing a Node3D (StaticBody3D with CollisionShape3D) these error message are displayed:

E 0:00:02:0733   update_polygons: Navigation map synchronization error. Attempted to update a navigation region with a navigation mesh that uses a different `cell_height` than the `cell_height` set on the navigation map.
  <C++ Source>   modules/navigation/nav_region.cpp:114 @ update_polygons()

E 0:00:19:0007   sync: Navigation map synchronization error. Attempted to merge a navigation mesh polygon edge with another already-merged edge. This is usually caused by crossing edges, overlapping polygons, or a mismatch of the NavigationMesh / NavigationPolygon baked 'cell_size' and navigation map 'cell_size'.
  <C++ Source>   modules/navigation/nav_map.cpp:770 @ sync()

In Godot v4.1.beta2 it worked, i.e. no error message

Steps to reproduce

GDScript:

@onready var _navigationRegion3D: NavigationRegion3D = %NavigationRegion3D

:

_navigationRegion3D.bake_navigation_mesh(false)

Properties NavigationRegion3D:

CleanShot 2023-06-22 at 19 15 44@2x

Minimal reproduction project

RTS 3D BakeIssue.zip

YuriSizov commented 1 year ago

cc @smix8

smix8 commented 1 year ago

You need to sync the cell_size and cell_height of your navigation mesh with the cell_size and cell_height set on the navigation map that uses the navigation mesh.

Since you changed the cell_height of the navigation mesh from the default 0.25 to 0.1 you also need to set the same value on the navigation map.

The second error is not new, just reworded. Since you did not add a MRP I can only guess but all points that you already had merge errors on your navigation map in Godot v4.1.beta2 and the newly added validations only make it more explicit.

If you do not sync navigation mesh and navigation map the navigation map can not rasterize your navigation mesh vertices and edges correctly if you have more of them in close proximity and you get edge merge conflicts (second error msg).

Set your cell_size with ProjectSettings navigation/3d/default_cell_size for the default 3D navigation map. You can use NavigationServer3D.map_set_cell_size() at runtime to set it for a specific map.

Set your cell_height with ProjectSettings navigation/3d/default_cell_height for the default 3D navigation map. You can use NavigationServer3D.map_set_cell_height() at runtime to set it for a specific map.

deezaster commented 1 year ago

Message 1 has now disappeared with the recommendations. Thank you.

But Message 2 remains:

E 0:00:19:0007   sync: Navigation map synchronization error. Attempted to merge a navigation mesh polygon edge with another already-merged edge. This is usually caused by crossing edges, overlapping polygons, or a mismatch of the NavigationMesh / NavigationPolygon baked 'cell_size' and navigation map 'cell_size'.
  <C++ Source>   modules/navigation/nav_map.cpp:770 @ sync()
smix8 commented 1 year ago

This error tells you that you have somewhere around your navigation map a lot of vertices in very close proximity, too close to be rasterized into the navigation map cells at the current cell size/height. The navigation map tried and failed to place the two vertices of an edge into cells because the cells where already occupied by two other edges.

As the error msgs tells this is usually caused by crossing edges or overlapping polygons or a mismatch of the cell size/height the navigation mesh was baked with and the navigation map cell size/height.

deezaster commented 1 year ago

Ok. But what I don't understand is that when I 'bake' in the editor, it works fine. Obviously it is only a problem if I add a StaticNode at runtime (as a child of the NavigationRegion3D Node) and then bake it.

And why did it work in beta2?

smix8 commented 1 year ago

I don't understand is that when I 'bake' in the editor, it works fine.

Those navigation meshes loaded in the scene might not cause conflict on their own, the NavigationServer also does not always process in the Editor compared to runtime where it processes every physics frame. The missing part might be only added at runtime that causes it e.g. polygon overlap or crossed edges what went wrong.

And why did it work in beta2?

This second error has not changed and the error msg existed since Godot 4.0 and before. Only the error wording has changed with Godot 4.1 beta3.

Without a MRP I can not tell you more what might be causing it.

deezaster commented 1 year ago

I uploaded a MRP.

Here the demo: https://github.com/godotengine/godot/assets/1539838/3c91b410-d181-48c4-ac3e-71e88822217f

smix8 commented 1 year ago

There was actually a bug, just in a very unexpected direction. Goes to show why adding a MRP is so important.

For now you can solve this by using NavigationMesh.clear_polygons() before the bake until the fix is merged.