0 votes

how can i access a var from another node

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

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()

by (1,100 points)

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.

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.