0 votes
in Engine by (91 points)

1 Answer

+1 vote

You can get any node in the tree by providing the correct path. Node paths work just like folders on your operating system. get_node("..") gets the node one level up and is equivalent to get_parent()

Let's say you have the following setup:

-NodeA
+-- ParentA
|    +-- ChildA
+-- ParentB
     +-- ChildB

Your script on "ParentB" wants to get "ChildA". The path is .. (goes up one level to "NodeA") followed by "ParentA/ChildA" You could write this in two ways:

var node = get_node("../ParentA/ChildA")
# or
var node = get_parent().get_node("ParentA/ChildA")
by (20,917 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 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 webmaster@godotengine.org with your username.