0 votes
asked Dec 10, 2019 in Projects by Yamz (42 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")
answered Dec 11, 2019 by kidscancode (13,084 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.