0 votes

Hello, I have a problem with a path node it saying that the path is null
I have a script called Enemy and I'm trying to get Players node position but it's not working

extends KinematicBody2D

func _physics_process(delta):
    print(get_node("root/MainScene/Player").position())

I also tried printing out the node path without the position it says [Object:null]

Godot version 3.3
in Engine by (24 points)

2 Answers

0 votes
Best answer

I fixed it, the issue was that I typed root/ instead of /root/ and also .position() doesn't work.

extends KinematicBody2D

func _physics_process(delta):
    var pos = get_node("/root/MainScene/Player")
    var pos2 = pos.position 
    print(pos2)
by (24 points)
+1 vote

According to this using absolute paths with get_node() requires the node to exist in the Scene tree. Your node is either note in the scene tree or your path is incorrect.

by (1,051 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 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.