Hmm, I see. I’ve written out this code in an attempt to replicate what they’re doing, and don’t seem to be getting any results. I’m getting an “Invalid Navigation Polygon” error, and unfortunately I’m not familiar enough with the system to really understand what could be going on.
Below I’ve pasted all my code. The only changes I’ve made to the scene is that I’ve removed the NavigationRegion2D and moved the TileMap to the top level of the node tree.
public partial class Navpath : Node2D
{
//from https://github.com/godotengine/godot-docs/blob/master/tutorials/navigation/navigation_using_navigationmeshes.rst#navigation-mesh-script-templates
NavigationPolygon poly;
Rid resourceRegionID;
Callable Call_Parse;
Callable Call_Bake;
NavigationMeshSourceGeometryData2D meshSource;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
meshSource = new NavigationMeshSourceGeometryData2D();
Call_Parse = new Callable(this, Navpath.MethodName.OnParseComplete);
Call_Bake = new Callable(this, Navpath.MethodName.OnBakeComplete);
resourceRegionID = NavigationServer2D.RegionCreate();
NavigationServer2D.RegionSetEnabled(resourceRegionID, true);
NavigationServer2D.RegionSetMap(resourceRegionID, GetWorld2D().NavigationMap);
CallDeferred(Navpath.MethodName.ParseSourceGeometry);
}
private void ParseSourceGeometry()
{
meshSource.Clear();
Node2D rootNode = this;
//parse obstructionoutlines from all child nodes of the root node by default
NavigationServer2D.ParseSourceGeometryData(poly, meshSource, this, Call_Parse);
}
private void OnParseComplete()
{
GD.Print("Parse complete");
Vector2[] Points = {new Vector2(0.0f, 0.0f),
new Vector2(500.0f, 0.0f),
new Vector2(500.0f, 500.0f),
new Vector2(0.0f, 500.0f)
};
meshSource.AddTraversableOutline(Points);
NavigationServer2D.BakeFromSourceGeometryDataAsync(poly, meshSource, Call_Bake);
}
private void OnBakeComplete()
{
GD.Print("Bake complete");
//update the region with the updated navmesh
NavigationServer2D.RegionSetNavigationPolygon(resourceRegionID, poly);
}
}