Why array path is empty?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nizil
onready var agent = $NavigationAgent2D
onready var player = get_tree().current_scene.get_node_or_null("Player")

func _physics_process(delta):
	if player_killed == false:
		set_path()

func set_path():
	agent.set_target_location(player.global_position)
	path = Navigation2DServer.map_get_path(agent.get_navigation_map(), position, agent.get_target_location(), false)

I don’t know why path variable is empthy, when I using map.get.path()

Presumably it can’t find a path from position to the target location?

SteveSmith | 2023-01-17 10:39

:bust_in_silhouette: Reply From: smix8

The function will return empty when you a) have no navigation mesh on the map b) you are calling the functions to early before the NavigationServer had time to sync, e.g. you are calling in a _ready() function while half the SceneTree is not even done loading. The NavigationServer syncs map changes on the physics frame so you need to at least wait one physics frame before you can query a path.