0 votes

Hi,

I have a Navigation2D node with two tilemap childs, tileMap and tileMap_Selection.

The idea was to try and find the shortest path from one tile to another, the tileMap doesn't have any navigation2D_polygon so I set all the tiles in tileMap_Selection to a tile which has a navigation2D_polygon.

If i set all tiles and then straight away ask for a path from one tile to another the resulting list of points is empty but if I wait for 0.1 seconds the list contains all points.

On the parent Navigation2D i have a script which has the following code:

func findTiles():
    var potentialTiles = tileMap.get_used_cells()
    for tile in potentialTiles:
        tileMap_selection.set_cellv(tile, 1)
    #yield(get_tree().create_timer(0.1), "timeout")
    print(get_simple_path(tileMap_selection.map_to_world(potentialTiles[0]), tileMap_selection.map_to_world(potentialTiles[1]), false))

with yield(get_tree().create_timer(0.1), "timeout") commented the output is [] whereas if it is uncommented the output is: [(4284, -88), (4391.5, 67.5), (4533, 126), (4536, 44)]

Is there a better was than to use yield(get_tree().create_timer(0.1), "timeout") in order for the get_simple_path function to use the updated tileMap_selection ?

Thanks a lot for any help you can provide,

in Engine by (33 points)

1 Answer

+1 vote
Best answer

try calling update_dirty_quadrants ( )on your tilemap instead of your yield

by (128 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.