godotengine / godot

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

Changing `NavigationRegion3D.navigation_mesh.cell_size` doesn't set up `NavigationServer3D` respective map to correct `cell_size` resulting in mismatch error #89271

Open razcore-rad opened 6 months ago

razcore-rad commented 6 months ago

Tested versions

v4.2.2.rc1.official [c7fb0645a]

System information

Ubuntu 23.04, Vulkan, NVIDIA GeForce RTX™ 2060 / NVIDIA GeForce RTX™ 2060, NVIDIA Driver Version: 525.105.17, NVML Version: 12.525.105.17

Issue description

This seems something similar to https://github.com/godotengine/godot/issues/83570, but for NavigationRegion3D/NavigationMesh.

ERROR: Navigation map synchronization error. Attempted to update a navigation region with a navigation mesh that uses a `cell_size` of 0.10000000149012 while assigned to a navigation map set to a `cell_size` of 0.25. The cell size for navigation maps can be changed by using the NavigationServer map_set_cell_size() function. The cell size for default navigation maps can also be changed in the ProjectSettings.
   at: update_polygons (modules/navigation/nav_region.cpp:128)

The error occurs when when:

  1. First ever creating a NavigationMesh with a different cell_size and then using Bake NavigationMesh. On subsequent recreations of NavigationMesh in the same Godot session the error doesn't occur.
  2. When opening a new Godot instance where a NavigationMesh.cell_size is different from the project properties default value.
  3. At runtime when NavigationMesh.cell_size is different from the project properties default value.

The workaround is to call NavigationServer3D.map_set_cell_size(get_navigation_map(), navigation_mesh.cell_size) somewhere in the code.

Steps to reproduce

Open the Minimal Reproduction Project and see the error first occur since I have assigned a NavigationMesh to NavigationRegion3D.navigation_mesh with a cell_size of 0.1 which is different from the default project properties of 0.25.

When you run the project you'll also get the error.

I've attached a workaround script to NavigationRegion3D which calls NavigationServer3D.map_set_cell_size(get_navigation_map(), navigation_mesh.cell_size) and fixes the error at runtime. This code is commented out for the purpose of demonstration.

Minimal reproduction project (MRP)

godot-dbg.zip

razcore-rad commented 6 months ago

Seems like something similar is happening with NavigationMesh.cell_height.

smix8 commented 6 months ago

If the map would react to every region with a navigation mesh that has a mismatch configuration that would be a cacophony of unexpected overrides.

razcore-rad commented 6 months ago

So I see this was marked as a discussion topic.

From a gamedev user of Godot perspective, is there ever a point of having out of sync navigation server maps properties (cell_size, cell_height, etc.) & navigation polygon properties? I don't see any scenario where we might want that possibility.

So doesn't it make sense to update the navigation server maps with the properties we define as users in the inspector? Instead of being forced to update/track everything manually and sync in code.

smix8 commented 6 months ago

From a gamedev user of Godot perspective, is there ever a point of having out of sync navigation server maps properties

No not really. There is no point in having them out of sync for a single navigation map as it only invites problems with merging edges.

The thing is that you can not enforce it outside the navigation server internals. The reality we live in is that a lot of users do not have their navigation meshes baked in sync with the same properties for the same map. Some love to have different properties for every single mesh to "make it look good" or fix certain surface areas instead of fixing the actual geometry that causes the bake problem.

Users can throw whatever NaviationPolygon or NavigationMesh they want at the server, there is not way to verify any of this upfront before it is used by an actual navigation map.

That is also why it does not verify on the region or mesh but on the internal navigation server map. Since it is the navigation map that needs to merge that polygon soup that users create it is also what dicates the conditions and settings and not the other way around.