Help my debugger says "get_simple_path" is a nonexistent function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LavaDrop

This script is used so an enemy follows the player around and when watching a video it said to use this line of code

func move_to(target_pos):
path = nav.get_simple_path(global_transform.origin, target_pos)
path_node = 0

But the debugger said “get_simple_path is a nonexistent function”
This is my entire code for the enemy

extends KinematicBody

var path =
var path_node = 0

var speed = 10

onready var nav = get_parent()
onready var player = $“…/NewFPS”

func _ready():

func _physics_proscess():
if path_node < path.size():
var direction = (path[path_node] - global_transform.origin)
if direction.length() < 1:
path_node += 1
move_and_slide(direction.normalized() * speed, Vector3.UP)

func move_to(target_pos):
path = nav.get_simple_path(global_transform.origin, target_pos)
path_node = 0

func _on_Timer_timeout():

:bust_in_silhouette: Reply From: jgodfrey

get_simple_path(...) is a valid function on a Navigation or Navigation2D node. In your code, you seem to be trying to get a reference to some kind of navigation node via:

onready var nav = get_parent()

I can only assume that the node being returned by get_parent() in this case is not the navigation node you think it is.

You haven’t shared your scene tree, but for that code to work, the above script would need to be associated with a node that is a child of the expected navigation node. I assume that’s not the case here.

To check that, I’d suggest that you verify the node that’s being stored in your nav reference. This should tell you…

func _ready():
    print('nav node is a ' + nav.get_class())

I assume you’ll find that it’s not a Navigation-type node… In that case, you need to reference the correct node.