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

Events node

Note

For versions 2019/2020 LTS, download the Visual Scripting package from the Unity Asset Store.

Scripting nodes listen for events. They are the starting point for all scripts and appear as special green nodes in graphs.

There are many kinds of events, grouped in sub-categories under the root Events category (fuzzy finder > Events).

Two simple common events are Start and Update, both located under Lifecycle.

  • Start is called once when the graph or event handler is first created.
  • Update is called at every frame while the graph or event handler is active.

New script machines start with both these events by default.

A new script machine with the two default events: On Start and On Update.

Inputs and Outputs

All events have a single Trigger control output that starts the script when they are triggered.

Value inputs are options that influence when the event is triggered. For example, some events have a Target setting that determines which object is listening to the event. Most often, you'll leave this setting at its default value of Self.

The value outputs on events are arguments that are passed from the event, giving you more information about what actually happened. For example, on the On Trigger Enter event, the other collider that is involved in the collision is an output.

An On Trigger Enter node with a collider as the output.

Custom Events

There is a special type of event, the Custom Event that triggers custom events across graphs, along with their custom arguments.

For example, to create a custom event called On Damage that gets called so the character loses health, the event should have one integer argument that indicates the amount of damage to inflict. Listen to the event by creating a Custom Event node (under Events). Set the name to On Damage. The set the argument count, below the name, to 1.

A custom event with one argument: an integer indicating the amount of damage to inflict

Note

Indices are zero-based, so the first argument is labeled Arg. 0.

To trigger the event from elsewhere, use the Trigger Custom Event node, located right under the Custom Event node in the fuzzy finder. Enter the name of the event exactly as it is sensitive to case and whitespace.

For example, to create a script machine on a boulder that could hit the player, use the force of the impact as the damage.

A script machine for a boulder that could hit a GameObject. It uses a Vector 3 Magnitude node to convert the force of the impact to the damage. The script machine has 3 nodes: an On Collision event node, a Vector 3 magnitude node, and a Trigger Custom event node. The Trigger output port of the On Collision event node connects to the Enter input port on the Trigger Custom event node. The Collider output port of the On Collision event node connects to the Target input port on the Trigger Custom event node. The Impulse output port on the On Collision event node connects to the  Vector input port on the Vector 3 Magnitude node. And the Result output port  on the Vector 3 Magnitude node connects to the Argument input port Trigger Custom event node.

The collider that's hit by the boulder is the target of our trigger; the On Damage event is triggered on all machines attached to that collider. Use the damage value to subtract health from the receiver object.

The Get Variable node provides the current health to the Subtract node, which outputs a new health value to the Set Variable node.

Custom events do not require a receiver and do not cause an error if there isn't a listener to handle them.

Animation Events

Use animation events to trigger script graphs when you reach a certain point in your animation. Select an object with a machine and an animator. Then, from the Animation window, add an animation event.

The Add Animation button in the Animation window.

With the event selected, choose TriggerAnimationEvent as the function from the Inspector.

Use any parameter from the Inspector.

In your script graph, add an Animation Event node (under Events >Animation).

There are two types of events:

  • a global animation event, and
  • a named animation event.

On the left, a global animation event node listens to all animation events on the object. On the right, a named animation event node with MyAction as the input.

The difference is that the first type listens to all animation events on the object and returns the string parameter. The second type's trigger is the string parameter that is equal to the specified name input.

Unity Events

Use Unity Events to trigger events that have been setup from the inspector. These are commonly found in GUI components like buttons, but they can also be created in your custom scripts.

Configure them by selecting an object with a machine and select the Trigger Unity Event method. In the string field, type the event name to listen to in the graph and in the graph, add a UnityEvent node with a matching name.

A UnityEvent node listens to a specified event from GUI components or scripts.

Additional arguments are not supported on Unity events.

Events API

Visual scripting provides a simple API to trigger custom events from C# script.

Add the following usings to your C# script to access the API.

using Unity.VisualScripting

Triggering API

A single method call is needed to trigger a custom event. Pass as many arguments as required.

CustomEvent.Trigger(targetGameObject, argument1, argument2, ...)

For example, you can trigger this custom event node:

A custom event node

With this line of code.

CustomEvent.Trigger(enemy, "Damage", 30);
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