DEV Community

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

Posted on • Updated on

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

Update: Godot's Visual Script will discontinue in Godot 4.0. Therefore, it's useless to continue using Visual Script in Godot now.

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

Top comments (0)