[Godot 4b10] When setting up 2D pathfinding on a tilemap, do I have to manually copy all the physics polygons as navigation polygons, or is there an easier way? Can I just do this programmatically at runtime?

Oh, hi! After a few hours of troubleshooting and sifting through documentation, I actually just managed to drill down and brute force it. I'm still interested if there's a right way to do it, because this is obviously ugly.

In a script for a scene inheriting TileMap:

func physics_to_navigation()->void:

for i in tile_set.get_source_count():

    var source = tile_set.get_source(i)

    for j in source.get_tiles_count():

        var id = source.get_tile_id(j)

        for layer in get_layers_count():

            var data :TileData= source.get_tile_data(id, 0)

            for physics_layer in tile_set.get_physics_layers_count():

                for poly in data.get_collision_polygons_count(physics_layer):

                    var nav_poly = NavigationPolygon.new()
                    var points := data.get_collision_polygon_points(physics_layer, poly)
                    nav_poly.add_outline(points)
                    nav_poly.make_polygons_from_outlines()
                    data.set_navigation_polygon(layer, nav_poly)
/r/godot Thread Parent