DEV Community

Cover image for How to get a variable value from another script, Godot's Visual Script
Archer Allstars
Archer Allstars

Posted on

How to get a variable value from another script, Godot's Visual Script

A lot of people who use Godot's Visual Script want to get a variable value from another script. Here's how!

Just drag and drop a scene node, which is attached to the script, into the canvas as shown in the screen recording below:

drag and drop a scene node

A proper way to do it

As it has been pointed out in my previous tutorial, it's better to use an instance mode unless you are OK to fix every nodes if anything goes wrong.

  • First, set a scene node that you want to get the variable from to an object variable in the _ready function which will be called only once.

set a scene node

  • Change set mode of the node to Instance. And put the object variable to the instance input port.

setup

I hope this helps 👍


Cover photo by olieman.eth on Unsplash

Discussion (0)