Topic was automatically imported from the old Question2Answer platform.
Asked By
JulioYagami
I would like to know how I could access a brother node easily and quickly. Suppose I have a root node called “main” and two other children “node1” and “node2”, and the latter has a variable that I want to access (could be eg “scale”), as I would do to access it, that of node1?
You can either make it a singleton by
Project Settings > Autoload. Then target your script. (If your talking about scripts)
Otherwise You’d Have to get the node.
like so
get_node("root/main/node1")
So I guess $“root/main/node1” would work, too. I was referring to picking up the node2, so I suppose the following function should work perfectly:
get_node("root/main/node2").scale = Vector2(1,1) # something you want to put
or:
$"root/main/node2".scale = Vector2(1,1) # something you want to put
The advantage is, you don’t need to setup a singleton and your node could be anywhere in the tree, it will still be able to access its sibling.
Not sure why singletons or root access were suggested, they seem overkill to me^^
Sorry Its how I’ve always managed to get things to work. The above has never worked for me at all