docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Listen to events

    If you want to do any monitoring or processing on incoming events yourself, subscribe to the InputSystem.onEvent callback.

    InputSystem.onEvent +=
        (eventPtr, device) =>
        {
            Debug.Log($"Received event for {device}");
        };
    

    An IObservable interface is provided to more conveniently process events.

    // Wait for first button press on a gamepad.
    InputSystem.onEvent
        .ForDevice<Gamepad>()
        .Where(e => e.HasButtonPress())
        .CallOnce(eventPtr => Debug.Log($"Button {eventPtr.GetFirstButtonPressOrNull()} pressed"));
    

    To enumerate the controls that have value changes in an event, you can use InputControlExtensions.EnumerateChangedControls.

    InputSystem.onEvent
        .Call(eventPtr =>
        {
            foreach (var control in eventPtr.EnumerateChangedControls())
                Debug.Log($"Control {control} changed value to {control.ReadValueFromEventAsObject(eventPtr)}");
        });
    

    This is significantly more efficient than manually iterating over InputDevice.allControls and reading out the value of each control from the event.

    In This Article
    Back to top
    Copyright © 2026 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)