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 :

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, create it with a default value if it hasn't. For example:

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 node gets the value of the health variable on the player2 object:

Is this article helpful for you?