Tilemap with Navigation2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By erasmo85
:warning: Old Version Published before Godot 3 was released.

Hello Godoters, how are you doing?
I have a little problem with a project of mine: I have this structure in the main scene (on the left in the image) with an instanced node (on the right), it generates a map of devices (computers, servers, ecc) using the TileMap node. Everything works fine except for one thing: when I want to connect one point to another with get_simple_path function of the Navigation2D (in the script of the MapControl node), the first time it returns me an empty array, from the second time on it works normally. The script in the MapControl node is like this:

extends Node
    
onready var map = get_node("../Navigation2D/TileMap")
onready var navigation = get_node("../Navigation2D")
var routersCoord = {}
var devicesCoord = {}
    
func _ready():
    regenerateMap()
    
func regenerateMap():
    ...
    #Make connection between router and servers
    var serverNumber = 1 + randi() % 4
    var src = map.map_to_world(routersCoord["router1"])
    var dest = map.map_to_world(devicesCoord["server"+str(serverNumber)])
    var points = navigation.get_simple_path(src,dest,false)

I hope it was clear, english is not my first language. Any thoughts?
P.S.: I’m creating the map dynamically, I mean that when I click on the TileMap node, it is always empty, it is created at runtime. If I fill the map from the editor with objects, the get_simple_path function works normally, at first shot. Is there a function to “close” or “finalize” the TileMap or is this a kind of bug?

edited for code looks better

volzhs | 2016-09-05 19:19

what do you mean “from the second time”?
how did you make the second time?

volzhs | 2016-09-05 19:24

The second time I run the function “regenerateMap()” in the same session.

erasmo85 | 2016-09-05 19:33

:bust_in_silhouette: Reply From: erasmo85

Nevermind, I found the solution here:

I add just the line:

get_node("TileMap")._update_dirty_quadrants()

before the “path” calculation and it’s done.