docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    See and record input event flow

    To record events flowing through the system, use this code:

    // You can also provide a device to only
    // trace events for a specific device.
    var trace = new InputEventTrace();
    
    trace.Enable();
    
    var current = new InputEventPtr();
    while (trace.GetNextEvent(ref current))
    {
        Debug.Log("Got some event: " + current);
    }
    
    // Also supports IEnumerable.
    foreach (var eventPtr in trace)
        Debug.Log("Got some event: " + eventPtr);
    
    // Trace consumes unmanaged resources. Make sure you dispose it correctly to avoid memory leaks.
    trace.Dispose();
    

    To see events as they're processed, use this code:

    InputSystem.onEvent +=
        (eventPtr, device) =>
    {
        // Can handle events yourself, for example, and then stop them
        // from further processing by marking them as handled.
        eventPtr.handled = true;
    };
    
    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)