+1 vote

this is my res:// :

res:
-enemy
    -goblin
        -goblin.tscn
-player
    -player.tscn

i am trying to get my players position in goblin.tscn script using :

onready var playerpos = get_node("../root/player/player") but it gives node not found error.

how to solve this error?

thankyou

in Engine by (26 points)

2 Answers

+1 vote

The get_node() function needs a node path based on the layout of the nodes in the scene, not in your res:// directory. Look out how the nodes are laid out in the "Scene" tab, not the "FileSystem" tab.

For example, if your scene had a node hierarchy like this:

  • Main

    • Goblin
    • Player

Your node path would be "../Player".

by (7,190 points)
+1 vote

what is your node structure? if you have both nodes as siblings in the node tree you can access the root node of the scene and then reference the player node

var player = get_parent().get_node("player")

or

get_node("/root/player")
by (430 points)
edited 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.