Closed mrTag closed 11 months ago
Thanks for the detailed report.
According to the error msg it is the other way around.
The navigation mesh has the correct cell size in that error. It is the navigation map that has the incorrect cell size.
By default both "2D" navigation map and NavigationPolygon have a cell size of 1.0, or at least they should have.
I didn't even notice that in the error message. But it didn't line up with my experience with the code and so I had a look at the code of the error message: https://github.com/godotengine/godot/blob/7f884b4e0017368e193d96f425aac6c2d8a86eb0/modules/navigation/nav_region.cpp#L128 and indeed: the two objects are the wrong way around in the format message! 🤦 The mesh cell size should be the first argument and the map cell size the second one.
Godot version
4.2 beta1
System information
Windows 10
Issue description
I was trying out the new 2D Navigation mesh baking features (great stuff, btw!) and immediately ran into an error after creating a
NavigationRegion2D
and a correspondingNavigationPolygon
(all in the editor/inspector) :I haven't changed any of the
cell_size
settings anywhere and I can't even set thecell_size
of theNavigationPolygon
to 0.25, since the inspector for that is integer based. So I had a look at the code and the culprit seems to be in the constructor of theNavigationPolygon
:The
navigation_mesh
is instantiated with its default values (cell_size
being 0.25!) and the real initialization, where thecell_size
is set, is then not executed, becausenavigation_mesh
is not null:So I removed the
navigation_mesh
instantiation from theNavigationPolygon
constructor and went on with my testing without any further hitch. As far as I knownavigation_mesh
is only accessed throughget_navigation_mesh()
, where it is then instantiated lazily, so the instantiation in the constructor is not needed. I implemented and tested a whole navigation system for our game based on theNavigationRegion2D
after that change and haven't noticed any problems (but I am only creating the navigation polygon at runtime viaNavigationServer2D.bake_from_source_geometry_data_async
, so maybe there are problems in other use cases 🤔).I just drafted a PR: https://github.com/godotengine/godot/pull/83568
Steps to reproduce
Minimal reproduction project
A reproduction project isn't really necessary, since the steps are so simple, but here is one anyway: NavigationRegion2DTest.zip (when you open the scene.tscn, you'll get the error as well)