This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hello everyone,

I try to access a function from my TileMap-Node through another Node2D-Node.
Both Nodes are under a scene/node called "game_window".
In the basic Node2D I wrote

onready var tilesetnode = getnode("/root/game_window/TileMap")

but it get the error message that the node isn't found. I got the path by displaying it with getpath(). The getnode() function only works for me when the node I try to access is a subnode, absolute paths don't seem to work.

Does anyone know why it doesnt work out?

in Engine by (31 points)

Two ideas:
Only refer to nodes that are children of the node you have as root for the scene. Don't try to refer to a higher-level node from a leaf. Accessing with an absolute path isn't needed.

If you use setget anywhere in the script, and those setters set things on referenced nodes... you'll probably encounter the exact problem I had. Godot runs setters on export variables before _init and _ready... so this works around that by killing the setter early if _ready has never been called.

var is_ready = false

var setter_thing setget set_setter_thing

var set_setter_thing(setter):
    if not is_ready:
    # whatever you need to do

var _ready():
    # everything needed on ready
    is_ready = true

1 Answer

+3 votes
Best answer

I've solved it by myself. I just start the path with "../" if the Nodes have the same place in the hierarchy.

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