How to handel node paths, get_node, find_node etc. correctly? How to find the correct paths?

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

The more I am working with godot the more often I run into trouble with handling nodes and their paths. Usually I run into the node not found error for several tries until I find a way to get things done or change my approach to avoid the hassle.
I thought the find_node() method should be good to avoid dealing with paths too much, but this one did not even work once for me.
For example: I have a door scene instanced in my world scene with a static body attached to it. When the door is opened, I want to remove the static body.
My door scene is structured like this:
StandardDoor(Control) > SDoor (Area2D > StaticBody2D
The script is attached to SDoor, so when I write the following code:

var body = find_node("StaticBody2D")
self.remove(body)

I would expect this to find the static body and remove it. Instead I get a node not found error.
This is just one of many issues I have with referring to nodes. (And btw yes, I read the docs, but this does not seem to be enough to understand it. At least not for me…)
Is there a quick and easy way to refer to nodes? Or a really good tutorial to understand this? I would really appreciate some help.

ok I just found out that in my provided example self.find_node() does the trick - so I actually need the owner.
Still this only resolves one issue and I will certainly run into a similar problem any time soon again.

Ciavarie | 2020-09-06 11:19

I also came up with an idea to iterate throw StandardDoor(Control) childs and check if it’s class is Godot.StaticBody : remove it. try this approach . But at first read the article i mentioned above

sirAlexDev | 2020-09-06 12:11