|To use Bolt, which is Unity’s visual scripting solution, you must purchase it on the Unity Asset Store.|
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.|
|SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary 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 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.
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.