docs.unity3d.com
  • Manual
  • Scripting API
  • Changelog
  • License
Show / Hide Table of Contents
  • About Visual Scripting
    • Configure project settings
      • Add or remove available nodes
      • Add or remove types
      • Create or restore a backup
    • Choose a control scheme
    • Configure your preferences
    • Update Visual Scripting
    • Version control systems
    • Use Visual Scripting with Unity Cloud Build
  • Basic concepts in Visual Scripting
    • The interface
    • Nodes
    • Graphs
      • Subgraphs and State Units
      • Transitions
    • Script Machines and State Machines
    • Object types
      • Custom types
    • Variables
  • Develop application logic with Script Graphs
    • Create a new graph file
      • Create a new blank graph with the Project window
      • Create a new unassigned graph with the empty graph creation flow
      • Create and assign a graph to an existing GameObject
      • Create and assign a graph to a new GameObject
      • Create a graph on a Script Machine or State Machine
    • Attach a graph file to a Script Machine or State Machine
    • Open a graph file
      • Add a node to a Script Graph
      • Connect nodes in a Script Graph
      • Create and add a variable to a Script Graph
      • Create node groups
      • Add comments to a graph
    • Add a Subgraph to a Script Graph
      • Add a Trigger or Data port to a Script Graph
    • Add a State Unit to a Script Graph
    • Custom Events
      • Add a Custom Event node
      • Add a Trigger Custom Event node
    • Capture user input in an application
      • Capture input using the Input Manager
      • Add and configure a Player Input component
      • Capture input using the Input System package
    • Use relations to debug
      • Predictive and live debugging
      • Working with debug messages
    • Live edit
      • Live edit during runtime
  • Develop logic transitions with state graphs
    • Create a new state
    • Create a transition between states
  • Advanced customization and development
    • Refactor a C# script with Visual Scripting
      • Add the RenamedFrom attribute to a C# script
    • Custom C# nodes
      • Create a new simple Custom C# node
      • Add ports to your Custom C# node
      • Add logic to your Custom C# node
      • Add relations to your Custom C# node
      • Add documentation to your Custom C# node
      • Custom C# node attributes reference
    • Create a Custom Scripting Event node
      • Create a Custom Scripting Event Sender node
      • Trigger a Custom Scripting Event from a C# script
      • Listen to a Custom Scripting Event from a C# script
    • Use a custom type
      • Add the Inspectable attribute to a custom type
      • Create a custom PropertyDrawer for a custom type
  • Node reference
    • This node
    • Control node
    • Time node
    • Events
      • Event nodes
      • Input Event nodes
        • On Input System Event Button
        • On Input System Event Float
        • On Input System Event Vector 2
        • On Button Input
        • On Keyboard Input
        • On Mouse Down
        • On Mouse Drag
        • On Mouse Enter
        • On Mouse Exit
        • On Mouse Input
        • On Mouse Over
        • On Mouse Up As Button
        • On Mouse Up
    • Variable node
    • Nulls node
    • Formula node
    • Nesting
      • Input node
      • Output node
      • State Unit node
      • Subgraph node
    • Script graph nodes
    • State graph nodes
  • Developer's guide
  • Known Issues

Graphs

A graph is a Visual Scripting asset that contains a visual representation of logic in an application.

Visual Scripting has two different types of graphs: Script Graphs and State Graphs. You can use either graph type in specific situations to define and change how GameObjects in an application behave. Script Graphs and State Graphs must be attached to a Script Machine or State Machine to be used in a project. For more information on Script Machines and State Machines, see Script Machines and State Machines.

Script Graphs

Script Graphs control and connect specific actions and values. The actions in a Script Graph happen in a specific order. Actions can happen every frame, or when a specific event occurs.

An example of a Script Graph opened in the Graph window. The output trigger port from an On Update Event node connects to the input trigger port on a Set Variable node, set to Flow. A Float Literal node with a value of 2.5 connects its output port to the data input port on the Set Variable node, which sets the value of the variable Count. The output trigger port on the Set Variable node connects to the input trigger port on a Debug Log node. The data output port on the Set Variable node connects to the A input port on a generic Add Inputs node. An Integer Literal node with a value of 1 connects its output port to the B input port on the Add Inputs node. The data output port on the Add Inputs node connects to the Message input port on the Debug Log node.

Visual Scripting represents the actions in a Script Graph through nodes. Connect nodes together with edges to tell your application what to do, and in what order.

Script Graphs can access a large collection of nodes, which correspond to different features and functionality in the Unity Editor. Access these nodes through the fuzzy finder.

Script Graphs define the specifics of what a GameObject does while your application runs.

State Graphs

A State Graph has states and gives the logic for when your application moves between states, through connections called transitions. Use State Graphs to design AI behavior or define scene and level structures.

A state is any set of behaviors that you want a GameObject to perform, represented as a Script Graph. Visual Scripting represents states in State Graphs through State nodes. A State node can link to a Script Graph with logic for your application to follow, or give another State Graph with additional transitions and State nodes.

An example of a State Graph opened in the Graph window

States and transitions in a State Graph tell your application when to change its behavior, based on an event or after it fulfills a condition.

For example, you might have an enemy character with Patrol and Chase states. The enemy character's actions can change from the actions in the Script Graph for the Patrol state to the actions for the Chase state after it detects the player character. The detection event for the enemy character triggers the transition between the two states.

State Graphs don't use the fuzzy finder. They use a specific set of State nodes, which are in the Visual Scripting context menu:

  • Script States contain a Script Graph. When an application triggers a Script State, Visual Scripting runs the logic in a Script State's attached Script Graph. Script States use On Enter State Event, On Update Event, and On Exit State Event nodes to control logic based on the current state.

  • Super States contain another, nested State Graph. A Super State can help you better organize a State Graph, and reuse states and transitions across multiple graphs.

  • Any States serve as a placeholder for any other state in a State Graph. You can use an Any State node and create a single transition to a new state, rather than create multiple transitions from other states.

  • Transitions connect Script States, Any States, and Super States. Transitions contain Script Graphs that tell your application when to switch from one state to the next. For more information, see Transitions.

You can set any Script State node or Super State node as a Start State. Any state marked as a Start State is automatically active when Visual Scripting runs a State Graph. You can also have multiple Start States in a single graph. The Super State, Start, and Script State nodes in the following example are all Start States.

An image of a State Graph opened in the Graph window with multiple Start States, highlighted with red boxes.

In This Article
Back to top
Copyright © 2025 Unity Technologies — Trademarks and terms of use
  • Legal
  • Privacy Policy
  • Cookie Policy
  • Do Not Sell or Share My Personal Information