Button not found by its path and I don't get why.

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

I have a Button inside a structure like this:
World > YSort > Player > Camera > CanvasLayer > Button
A script is attached to it and inside this script I try to reference the button by:var this_button = get_node("YSort/Player/Camera2D/CanvasLayer/CombItemButton") inside the _ready() function
Whenever I start my project it crashes with the error message:
E 0:00:02.559 get_node: Node not found: YSort/Player/Camera2D/CanvasLayer/Button.
<C++ Error> Condition “!node” is true. Returned: __null
<C++ Source> scene/main/node.cpp:1381 @ get_node()
Button.gd:4 @ _ready()

Next I tried to get the button by.
get_tree().get_root().find_node(“Button”)
Unfortunately this holds the same result and as I just started with godot I am kind of out of alternative solutions I can come up with.
I would gladly appreciate any attemt to help me out.

:bust_in_silhouette: Reply From: klaas

Hi,
well …´for the first issue … its surely the wrong path. when both scripts are under the same parent it would be get_node(“…/CombItemButton”)

For the second issue … get_tree().get_root().find_node(“Button”,true,false)
you have to enable recursive search and set owner false.

Well I copied the path from the buttons right click in the editor. It worked for everything else, but this time it did not.

I’ ll try out your suggestion. Thank you.

Ciavarie | 2020-09-01 20:04