docs.unity3d.com
    Show / Hide Table of Contents

    Variables

    Note
    To use Bolt, which is Unity's visual scripting solution, download it from 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:

    Kind Description
    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

    1. Choose the tab corresponding to the kind of variable you want to add
    2. Type the name of the new variable in the New Variable Name field
    3. Click the plus button
    4. Choose its type
    5. (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 be 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.

    Removing Headers

    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 Edit > Preferences > Bolt.

    Dynamic Variables

    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:

    Visibility

    Note that all object variables in Bolt are public and can be accessed by other objects.

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023