0 votes
if Input.is_action_just_pressed("ui_down"):
    var spear = SPEAR.instance()
    spear.position = $Position2D.global_position

The code worked until I added the position line. Can anyone tell me why this has happened?

in Engine by (20 points)

Is there an error-message?
Is Position2D a child of the node with this script?

Yes it is a child of the node with this script. There is no error message when I try and shoot.

1 Answer

0 votes
Best answer

I think you don't have the Position2D as a direct child of the node that has this script. You may have to add it to your scene, or just add another path.
for example instead of the commend "$Position2D" you may have to use:


I'm just saying, that you can't call a properity of a node, if it doesn't exists on the path, that you're giving to the function.
With this little information i could only guess the answer, but I hope it helped ;)

by (137 points)
selected by
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 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.