how can i access a var from another node

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

how can i access a var from another node

:bust_in_silhouette: Reply From: aXu_AP

To access any object’s properties (variables), use dot syntax: object.variable
To get access to another node, there are few ways to do it. In this example, script is in the root node and it has child named Sprite which has declared var my_variable:

$Sprite.my_variable = "Hello!"

You can also search other nodes by name with find_node()

Not sure if this is considered bad form, but I also utilized get_parent().my_variable or similar for when I have dynamic but expected relationships between scenes.

Definitely_Human | 2022-12-10 20:00

1 Like