Variables are containers. Each variable has a name, a type, and a value.
The value inside a variable can change during runtime, which is why they're called vary-ables.
In Bolt, there are 6 kinds of variables:
|Flow Variables||Flow variables which are the equivalent to local variables.|
|Graph Variables||Graph variables are local to an instance of a flow graph. They have the smallest scope and cannot be accessed or modified outside their graph.|
|Object Variables||Object variables belong to a game object. They are shared across all graphs on that game object.|
|Scene Variables||Scene variables are shared across the current scene.|
|Application Variables||Application variables persist even when the scene changes. They will be reset once the application quits.|
|Saved Variables||Saved variables will persist even after the application quits. They can be used as a simple but powerful save system. They are saved in Unity's player prefs, which means they unfortunately can't refer to Unity objects like game objects and components.|
The variables window
The variables window can be opened via Windows > Variables. It contains one tab per kind of variable. The graph tab is only enabled if a flow graph is selected, and the object tab is only enabled if a game object is selected.
Adding a variable
- Choose the tab corresponding to the kind of variable you want to add
- Type the name of the new variable in the New Variable Name field
- Click the plus button
- Choose its type
- (Optional) Change its default value
Saved and Initial Variables
You may notice that under the Saved tab, there are two sub-tabs: Initial and Saved.
In the initial tab, you define values that will automatically created for new games.
In the saved tab, you can see the state of saved variables for your current computer. You can edit these manually or delete them all if you want to start anew.
Once you get a good grip of how each kind of variable works, you can remove the headers in the variables window to save some screen real-estate. Simply uncheck Show Variables Help in Tools > Bolt > Editor Preferences....
Variables don't need to be declared during edit mode! They can also be created during play mode.
Setting the value of a variable that doesn't exist automatically creates it. For example, this graph would create a new saved integer variable named gold with a value of 250, even if we hadn't defined it before:
Note that all object variables in Bolt are public and can be accessed by other objects.