docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class EventBus

    A global container that maps Event names and Component references to actions for registered listeners.

    Inheritance
    object
    EventBus
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.VisualScripting
    Assembly: Unity.VisualScripting.Core.dll
    Syntax
    public static class EventBus
    Remarks

    It is the EventMachine base class for ScriptMachine and StateMachine that triggers events. This overrides almost all Unity callbacks (such as Awake, OnEnable, Update, etc.) and triggers an event on the EventBus.

    Examples

    The following example shows how to use the EventBus to send a custom event from a script to a node in a graph. It also shows how to use the EventBus as a global event manager by executing a callback in a script, not just a node.

    For more information on how to create custom event nodes refer to the User Manual.

    In this example we've added some code to a GameObject. This code checks for when the user presses a sequence of keys to enable a cheat code, then triggers the CheatCodeActivated event. We register the CheatCodeActivated event in the Start method. The Update method triggers the event twice with 2 different targets: one for the CheatCodeActivated callback and the other to trigger the CheatCodeEnabled Node.

    The CheatCodeEnabled Node:

    Methods

    Register<TArgs>(EventHook, Action<TArgs>)

    Declaration
    public static void Register<TArgs>(EventHook hook, Action<TArgs> handler)
    Parameters
    Type Name Description
    EventHook hook
    Action<TArgs> handler
    Type Parameters
    Name Description
    TArgs

    Trigger(string, GameObject)

    Declaration
    public static void Trigger(string name, GameObject target)
    Parameters
    Type Name Description
    string name
    GameObject target

    Trigger(EventHook)

    Declaration
    public static void Trigger(EventHook hook)
    Parameters
    Type Name Description
    EventHook hook

    Trigger<TArgs>(string, GameObject, TArgs)

    Declaration
    public static void Trigger<TArgs>(string name, GameObject target, TArgs args)
    Parameters
    Type Name Description
    string name
    GameObject target
    TArgs args
    Type Parameters
    Name Description
    TArgs

    Trigger<TArgs>(EventHook, TArgs)

    Declaration
    public static void Trigger<TArgs>(EventHook hook, TArgs args)
    Parameters
    Type Name Description
    EventHook hook
    TArgs args
    Type Parameters
    Name Description
    TArgs

    Unregister(EventHook, Delegate)

    Declaration
    public static void Unregister(EventHook hook, Delegate handler)
    Parameters
    Type Name Description
    EventHook hook
    Delegate handler
    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
    • Your Privacy Choices (Cookie Settings)