How to instance navigationpolygoninstance in script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MathmoNerd123

I’m creating my maps with a random walker system similar to Heartbeast’s and am trying to set up navigation with the navigation 2D node for this. I got it to work fine with a handmade navigationpolygon but obviously I cant handmake it for a randomly generated map. I haven’t been able to find anything about this in Docs or online.
I have tried setting up navigation on the tileset but that didn’t work. Should it?

:bust_in_silhouette: Reply From: smix8

Change the polygons inside your NavigationPolygon resource with a script. You can either add vertices and matching polygons arrays or you can define outlines arrays and use make_polygons_from_outlines() to create a procedual navigation polygon. It is important to note that you polygon edges can not intersect and if you use outlines the outlines can not overlap and intersect.

When you finished changing the NavigationPolygon you need to first set the current NavigationPolygonInstance navpoly = null before you apply the changed polygon, else the update will be blocked cause it is still the same resource.

TileMap baked navigation is highly inefficient for this, don’t use it.