Skip to content

Variables

In Visual Scripting, a variable is used to store values into and read values from during the lifetime of a Script. The value is stored temporarily until the Script finishes running, and cannot be accessed from outside the Script. See the Use Cases and Limitations of variables to know more about what variables can and cannot do.

Creating Variables

Most interactions with variables are done in the Variables Panel on the right side of the Script View. A variable can be added by first clicking on the plus icon at the top of the Variables Panel, inputting a Name and variable Type, and finally clicking on the green + Add Variable button. Once a variable is added, depending on its type, a default value can be set to it.

Creating variables

Using Variables

Once a variable is created, it can be interacted with in the Script through these nodes:

  • Get Variable Node - Gets the value stored in a variable and outputs it through its Value Output Port. The type of the Output Port depends on the type of the variable.
  • Set Variable Node - Takes the input from its Input Port and stores it into the associated variable. The type of the Input Port depends on the type of the variable.

These nodes can be created by first going into the variable in the Variables Panel and dragging on the three vertical dots to the left of the variable name. While dragging, simply drop it into the Script View and select the node you need.

Animation showing how to create variable nodes

The Number and Long variable types have two other variable-specific nodes:

  • Increment Variable Node - Increases the value stored into the variable by the value from the Delta Input Port. The type of the Input Port depends on the type of the variable.
  • Decrement Variable Node - Decreases the value stored into the variable by the value from the Delta Input Port. The type of the Input Port depends on the type of the variable.

Use Cases

There are a few compelling use cases for variables that makes them worth knowing about and using.

Cleaner Scripts

Once you start adding more nodes and building up your Scripts, you may encounter the problem of linking your Value Ports between nodes far away from each other and having to create a tangled mess of links to make it work.

Utilizing variables properly will allow you to create cleaner and easier to understand Scripts. With variables, you can temporarily store an outputted value from one part of your Script and use this value on another part of your Script to prevent crisscrossing links.

Variables can also help you structure your Script to better follow the steps that your Script will do without having to worry about the Value Flow of your Script.

Keeping Track of Values

Once you start using some special Control Flow nodes, you may find the necessity to monitor and retain values during the execution of your program. This is particularly evident when employing calculations within a loop, such as iterating through a List using a For Each Node. To facilitate this, the use of variables becomes indispensable, allowing you to store and manage values computed during each iteration of the loop. This ensures a systematic approach to handling data and enhances the overall efficiency of your workflow.

Limitations

It is crucial to be aware of certain limitations when working with variables in your scripting endeavors. Firstly, variables are not accessible between Scripts, including Inner Scripts. This means that their scope is confined to the Script in which they are defined. In addition, currently there is no way of creating global variables that are accessible throughout all your Scripts, all the time.