Navigation agent empty path

Godot Version

4.2.1 Stable

Question

My navigation agent cannot generate the path, and I cannot figure out how to get around it.

I’ve tried telling the navigation agent to wait before initializing it, I have set up the navigation layer, the agent knows where it’s starting from and where it’s supposed to go, but the path array ends up being empty.

Full description wiht pictures:
https://www.reddit.com/r/godot/comments/1eafvuk/cant_get_navigation_agent_to_build_the_path/

Code (the required parts):
extends CharacterBody2D

u/export var target : Area2D = null

@onready var navigation_agent_2d = $NavigationAgent2D

var movespeed = 50

func _ready():
set_color()
call_deferred(“set_target”)

func set_target():
await get_tree().physics_frame
if target:
navigation_agent_2d.target_position = target.global_position

func _physics_process(_delta):
if target:
navigation_agent_2d.target_position = target.global_position

await get_tree().physics_frame
var current_agent_position = global_position
var next_path_position = navigation_agent_2d.get_next_path_position()
velocity = current_agent_position.direction_to(next_path_position) * movespeed

if navigation_agent_2d.is_navigation_finished():
return

print(current_agent_position)
print(next_path_position)
print(navigation_agent_2d.target_position)

move_and_slide()

Blockquote

What ends up happening in your case here is that an agent that uses the default map does a path query for the empty map because your entire navigation mesh was setup to exists on a different TileMap layer “road” navigation map.

Each TileMap navigation layer is its own navigation map as you can not stack or overlap navigation meshes. The navigation system does not support stacking navigation mesh surfaces on the same navigation map full stop, no excuses.

So either you start to juggle your agents between different TileMap layer maps or you just dump that entire TileMap layer concept when it comes to navigation meshes and have everything on just one “layer”. A single “layer” is what is actually supported by the navigation system, everything else is just TileMap make-believe.