Version: 2019.3
Events
Nulls

Variables

Note
To use Bolt, which is Unity’s visual scripting solution, you must purchase it on the Unity Asset Store.

There are 5 kinds of variable units, one for each kind of Variable.

For each of these, there are 3 units:

  • Get, to retrieve the value of the variable
  • Set, to assign a new value to the variable
  • Is Defined, to check whether the variable is defined

They are all found under the Variables category in the fuzzy finder :

You can easily spot variable units in the graph because of their teal coloring.

Dynamic Typing

One important thing to remember for the get / set units is that variables are not statically typed, meaning their type can change at runtime. This is why their type displays as object even if you defined them from the variables window.

Get Variable

The get variable unit requires the Name of the variable as an input and returns the Value as an output.

Set Variable

The set variable units require the Name of the variable and the new Value you want to assign to it as inputs. For convenience in layouting, it returns this same value as an output.

Note that you have to connect the control input port to indicate when the variable should assigned, and optionally the control output port to indicate what to do after.

If a variable with that name doesn’t yet exist, using a set node will create it .

Is Variable Defined

The is variable defined units require the Name of the variable as an input and return return a Is Defined boolean an output.

They are useful to check if a variable has been created, and often, provide a fallback value if it hasn’t. For example:

Note that you can do the same thing more easily by checking the Fallback box in the graph inspectorA Unity window that displays information about the currently selected GameObject, Asset or Project Settings, alowing you to inspect and edit the values. More info
See in Glossary
for a Get Variable unit. This will add a Fallback input to the unit that will be returned if the variable hasn’t been defined:

Dynamic Variables

Because the Name of the variable is a standard value input port, you can connect it to any other port that returns a string. This means that you can refer to “dynamic variables”, that is, variables whose reference may change during play mode.

Object Variables

Object variable units require an additional input for the Source. That port indicates on which game object the variable you’re referring to is defined. When left at its default value, they will look on the current object (self).

For example, this unit gets the value of the health variable on the player2 object:

Dropdowns

You can use the kind and the name dropdowns to quickly configure the variable units.

The name suggestions are contextual. They are based on the existing variables of this kind and on the other variable units in the current graph.

Drag and Drop

You can drag & drop items from the variable window directly into the graph to create matching units.

  • By default, a Get unit will be created.
  • If the Alt key is held, a Set unit will be created.
  • If the Shiftkey is held, an Is Defined unit will be created.
Events
Nulls