# Variables Variables act as a container for a piece of information that might change as your application runs. To define a variable, you by provide it a name, such as `MyVariable`; the type of data the variable holds, such as `int` or `string`; and a value, such as `1` or `cat`. In Visual Scripting, you can give the node the name of a variable, instead of a fixed value or text when you run your Script Graph. Your Script Graph uses the variable's name to access its value. For example, you could have a variable called `Count`, with an `int` type and a value of `1`. You could use an `Add` node in Visual Scripting to add 1 to the value of `Count`, and save the new value in `Count` to use again in another part of your Script Graph, or another separate Script Graph. Variables also have scopes. A variable's scope determines what parts of your Script Graph can access which variables to read or modify their values. The scope can also determine whether another Script Graph can access a variable. You can create and manage variables in your graph from the Blackboard. For more information on the Blackboard, see [the Blackboard](vs-interface-overview.md#the-blackboard). ## Variable scopes Each variable scope has its own tab on the Blackboard, except Flow variables. Visual Scripting has six variable scopes:
Variable Scope | Property |
---|---|
Flow Variables | Flow variables are like local variables in a scripting language: they have the smallest scope. You can't use a Flow variable if:
|
Graph Variables | Graph variables belong to a specific Script Graph. You can't access or modify Graph variables outside the specific Script Graph where they're defined. You also can't create a new Graph variable unless you have a Script Graph open in the Graph window. |
Object Variables | Object variables belong to a specific GameObject. You can edit an Object variable from the Unity Editor's Inspector for the GameObject, and the Object variable is accessible in all graphs attached to the GameObject. You can't create a new Object variable unless you've opened your Script Graph from a Script Machine component on a GameObject. |
Scene Variables | Scene variables belong to the current scene. Visual Scripting creates a new GameObject in your scene to hold references to your Scene variables. You can access your Scene variables from any Script Graph attached to a different GameObject in a single scene, but can't access a Scene variable in another scene in your project. |
App or Application Variables | Application variables belong to your entire application. You could access an Application variable across multiple scenes while your application is running, and the Application variable would hold your changes. Any values held in an Application variable reset to their default values once your application quits. |
Saved Variables | Saved variables are like Application variables, but they persist even after your application quits. You can use a Saved variable as a simple but powerful save system. Unity stores Saved variables in its PlayerPrefs , and they don't refer to Unity objects, like GameObjects and components. For more information on PlayerPrefs , see the Unity Scripting API section on PlayerPrefs. |