0 votes

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():

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?

in Engine by (27 points)
edited by

edited for code looks better

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

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

1 Answer

0 votes

Nevermind, I found the solution here:


I add just the line:


before the "path" calculation and it's done.

by (27 points)
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 Frequently asked questions and 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 [email protected] with your username.