Unable to get properties from an export (NodePath) variable

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

I have been using a export variable to get a nodepath and when ever I try to get properties from it the program crashes. I have it defined in the inspector, and it’s set to a kinematic body which has a global_position, but whenever I try to run this code:

extends Position2D

export (NodePath) var target 

func _physics_process(delta):

I get this error:

Invalid get index 'global_position' (on base: 'NodePath').

I’m very confused, and any help would be appreciated.

:bust_in_silhouette: Reply From: umma

you didn’t assign a value to target, try doing something like this:

export var target = ""

it will export this " " just write the name of the node you want “area2d”

I understand that, but given that its an export variable, wouldn’t I be able to get the same effsct by assigning it in the inspector?

Major_Monkey_0720 | 2022-01-30 23:43

what node were you trying to get global position for?

umma | 2022-01-31 00:21

:bust_in_silhouette: Reply From: rossunger

A nodePath is just a string. If you want to access the actual node, you need to get_node(target)