Issue extracting Navigation Path Array and using it to create 3D line

Godot Version

4.2

Question

I am creating a click to move function in my game, and have successfully used NavigationAgent3D and NavigationMap3D to move my character to places in the world by clicking. What I want to do now is show the intended path before clicking. The step I had planned to get me there was to show a 3D line , a line I would create using coordinates extracted from the navigationAgent3D.get_current_navigation_path() PackedVector3Array.

Here is a snippet of my GDScript code:

func set_target_position(origin: Vector3, target: Vector3):
	nav_agent.set_target_position(target)
	#print("pathfindcomponent: set_target_position")
	
	var path_array: PackedVector3Array = nav_agent.get_current_navigation_path()
	print(path_array.size())
	for i in path_array.size():
		print(path_array[i])

When I run this, the printed array is simply . When checking size of the array, it returns 0.

What am I missing with get_current_navigation_path? Is there a better way to go about doing this? I am able to turn on debug and see the debug line, which is sort of what I am going for. Does this require digging into NavigationServer3D?

so this print nothing?
how about print(path_array)?

change to this

func set_target_position(origin: Vector3, target: Vector3):
	nav_agent.set_target_position(target)
	#print("pathfindcomponent: set_target_position")
	nav_agent.get_next_path_position()
	var path_array: PackedVector3Array = nav_agent.get_current_navigation_path()
	print(path_array.size())
	for i in path_array.size():
		print(path_array[i])

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.