"node not found" error appears when I try to load a node with get_node()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By obstsalat

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 tileset_node = get_node(“/root/game_window/TileMap”)

but it get the error message that the node isn’t found. I got the path by displaying it with get_path(). The get_node() 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?

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

Jimmio92 | 2019-07-25 01:15

:bust_in_silhouette: Reply From: obstsalat

I’ve solved it by myself. I just start the path with “…/” if the Nodes have the same place in the hierarchy.