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.
0 votes

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.

in Engine by (57 points)

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.

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

Please log in or register to answer this question.

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.