Search Unity

Best practices:input system handle button touch/tap and then mark InputEventPtr has handled?

Discussion in 'Input System' started by ManjitSBedi, Jul 14, 2021.

  1. ManjitSBedi

    ManjitSBedi

    Joined:
    Mar 8, 2014
    Posts:
    58
    I am working on a project that uses touch events and button touches on mobile devices.

    There are some buttons in the UI that are floating above a tile map in a scene. We have an OnFingerUp event handler for touch events. When a button touch is released or up, a finger up event is propagating to the handler. We want to get touch events when a touch is ended over a tile in the tile map etc.

    Code (CSharp):
    1.             // Register callback for on finger up event
    2.             Touch.onFingerUp += OnFingerUp;
    This is what I am trying to work out the best way to handle:

    - user touches and releases a UI button
    - somehow mark input event as being handled
    - event is not propagated to OnFingerUp handler

    I saw this code snippet in the Input system documentation:
    Code (CSharp):
    1. InputSystem.onEvent +=
    2.         (eventPtr, device) =>
    3.         {
    4.             // Can handle events yourself, for example, and then stop them
    5.             // from further processing by marking them as handled.
    6.             eventPtr.handled = true;
    7.         };
    8.  
    Is this what I should be using and how I catch button touch events in this handler? I have been scouring the documentation for more info .