Error spam with NavigationAgent2D

Godot Version

Godot 3.5.3


I have endless error spam with NavigationAgent2D, and the final position of set_target_location does not change.

Here is the code:

func _ready():
nav =	nav.set_target_location(Vector2(get_global_mouse_position().x,get_global_mouse_position().y))

func _process(delta):
if !nav.is_navigation_finished():
			var current_agent_position: Vector2 = global_position
			var next_path_position = nav.get_next_location()

			velocity = current_agent_position.direction_to(next_path_position).normalized() * get_parent().speed

Here is the error that appears endlessly upon startup:
get_next_location: Condition “agent_parent == nullptr” is true. Returned: Vector2()
<Исходный код C++>scene/2d/navigation_agent_2d.cpp:345 @ get_next_location()
<Трассировка стека>Character.tscn::11:43 @ _process()

The NavigationAgent2D node requires a parent Node2D inheriting node to function.

Your NavigationAgent2D has no parent, that is your error and the source of your error spam.

1 Like

It turns out I forgot to add a node using code.
Thank you, by the way, for your work on navigation! :slight_smile:

1 Like