Godot Version
4.4.1.stable
Question
TL;DR
How to force a reload of custom collision or NavigationPolygons generated at runtime for TileMapLayers?
My Situation
I procedurally generate the TileMapLayer. I save the TileMapLayer using NodeDataResource
and the PackedByteArray
property called tile_map_data
:
class_name TileMapLayerDataResource
extends NodeDataResource
@export var tile_map_data: PackedByteArray
func _save_data(node: Node2D) -> void:
super._save_data(node)
var tilemap_layer: TileMapLayer = node as TileMapLayer
tile_map_data = tilemap_layer.tile_map_data
func _load_data(window: Window) -> void:
var scene_node = window.get_node_or_null(node_path)
if scene_node != null:
var tilemap_layer: TileMapLayer = scene_node as TileMapLayer
tilemap_layer.set_tile_map_data_from_array(tile_map_data)
What does work
Saving and loading the world works. All tiles are placed correctly, all collision shapes displayed (when debugging mode is on) so everything seems to exist.
What does not work
The navigation is not being baked correctly. It seems that the collision shapes are not recognized by the navigation server and the NavigationPolygons have a size of 0.
The navigation-code itself works, because creating a new world by setting the tiles with set_cells_terrain_connect
does result in the navigation baking correctly. Only loading the tilemap from file does not.
My question
How do I get the collision shapes to be recognized by the NavigationServer during baking?
I know there might be an issue of frame order and deferring. I added a custom keyboard input to manually trigger the navigation rendering. So the delay is definitely not the issue here.
What is my guess
From a google research it seems there was a method update_dirty_quadrants
on the TileMap
which forced a reload of collision shapes of some sort. But TileMapLayer
does not have such a method or at least I’m unable to find it.
Tutorials & Examples I used
Navigation Example
Navigation Example Explanation
Saving & Loading Tutorial