+1 vote

this is my res:// :


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?


in Engine by (28 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 (8,150 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")


by (452 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 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 [email protected] with your username.