0 votes

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):
    print(target.global_position)

I get this error:

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

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

in Engine by (41 points)

2 Answers

0 votes

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"

by (366 points)

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?

what node were you trying to get global position for?

0 votes

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

by (1,290 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.