docs.unity3d.com
    Show / Hide Table of Contents

    Variables

    Note
    For versions 2019/2020 LTS, download the visual scripting solution from the Unity Asset Store.

    Variables are containers. Each variable has a name, a type, and a value. There are six types of variables in visual scripting:

    Variable type Description
    Flow Variables Flow variables are the equivalent to local variables.
    Graph Variables Graph variables are local to an instance of a script 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 are reset once the application quits.
    Saved Variables Saved variables 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 don't refer to Unity objects like game objects and components.

    Values in saved and initial variables

    Under the Saved tab, there are two sub-tabs: Initial and Saved.

    • In the initial tab, define values that are automatically created for new games.

    • In the saved tab, the state of saved variables for the current computer is displayed. Edit these manually or delete them all to start over.

    Setting values in dynamic variables

    Setting the value of a variable that doesn't exist automatically creates it. For example, the following graph creates a new saved integer variable named gold with a value of 250, even though it has not been previously defined.

    Variables can be declared during edit mode or created during play mode.

    Variable's Visibility

    All object variables in visual scripting are public and can be accessed by other objects.

    In This Article
    • Values in saved and initial variables
    • Setting values in dynamic variables
    • Variable's Visibility
    Back to top
    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