Godot Version
Godot_v4.3-beta3_mono_win64
Question
Hey all,
I’ve been working on baking nav regions procedurally using this change:
Add NavigationPolygon `border_size` property for tile baking by smix8 · Pull Request #87961 · godotengine/godot · GitHub to chunk my map into regions for baking. Right now I’m just trying to get the initial generated map parsed and baked before moving onto dynamically updating each chunk.
So I have the following nav region output from my baking and parsing of obstacles + a traversable region covering the whole map.
The yellow rect is my BakingRect, the white square is what I expect the nav region to encompass when using the BakingRectOffset of 128,128.
Should the Offset not cut into the BakingRect by 128px on all sides? Did I misunderstand? I’m hoping someone very knowledgeable like @smix8 has time to explain to me. My goal is to have the first image look like the screenshots from the PR where the sections in between the squares is cut out so that other white squares will line up on the exact same pixel column and can be merged without using edge connections.
Two related but less important questions:
- Before running the following line I added a traversable outline to the sourceGeometry:
NavigationServer2D.ParseSourceGeometryData(newNavigationPolygon, sourceGeometry, GetNode(“ObjectTileMapLayer”), new Callable(this, nameof(OnChunkSourceGeometryParsed)));
However when the callback function OnChunkSourceGeometryParsed runs that TraversableOutlines array is empty and I have to re-add the outline. I.e. It works fine if I add the outline in OnChunkSourceGeometryParsed but not if the outline is added before parsing. Does the parsing of the collision obstacles create a new sourceGeometry? The docs say it adds to the sourceGeometry not replaces.
- After I run the following line:
NavigationServer2D.BakeFromSourceGeometryData(newNavigationPolygon, sourceGeometry, new Callable(this, nameof(OnChunkBakingDone)));
During OnChunkBakingDone I make calls to NavigationServer2D to create a region and set values like:
nextNavigationRegionRid = NavigationServer2D.RegionCreate();
NavigationServer2D.RegionSetEnabled(nextNavigationRegionRid, true);
NavigationServer2D.RegionSetMap(nextNavigationRegionRid, GetWorld2D().GetNavigationMap());
NavigationServer2D.RegionSetUseEdgeConnections(nextNavigationRegionRid, false);
NavigationServer2D.RegionSetNavigationLayers(nextNavigationRegionRid, 1);
NavigationServer2D.RegionSetNavigationPolygon(nextNavigationRegionRid, newNavigationPolygon);
However the NavRegions leak when I close the running app which implies to me that the created regions are orphaned nodes. Plus I am unable to see the regions created this way even with Visible Navigation turned on. They do seem to be working properly as my test unit paths around.
When I instead create the regions like this:
var region = new NavigationRegion2D();
region.UseEdgeConnections = false;
region.NavigationLayers = 1;
region.SetNavigationPolygon(newNavigationPolygon);
region.Enabled = true;
AddChild(region);
It is visible in debug mode and I am able to both see them in the node tree mid run and I don’t get a leak. From what I’ve read NavigationServer is the preferred way to create and modify regions (with RIDs) so is there some aspect I missed of creating them?
Thank you for your time all!