Mobile: Button Release not triggered

On mobile, releasing my on-screen button does not fire an input event. But on desktop, it does fire the event correctly. How can this be addressed, please?


Here’s my setup: As part of my UI Canvas, I have a UI Button that has Unity’s On-Screen Button component with the Control Path set to Button South [Gamepad].

8198196--1069182--Screenshot 2022-06-11 at 21.50.58.png

In my Input Actions, I have an Action called Drive. It has the Action Type set to Button. Under Interactions, I have added Press with the Trigger Behaviour set to Press and Release. This Action has a Binding set to Button South [Gamepad].

When I test this on desktop, the input event will be fired both when the button is pressed and when it is released. It works fine both for keyboard and gamepad. But when I test it on Android, the input event will only be fired when the button is pressed - but not when it is released. This also is reflected when logging the context.

public void OnDrive(InputAction.CallbackContext context)
    {
        Debug.Log(context);
        driveInput = context.ReadValue<float>();
    }

Desktop log:

When pressed:

When released:

Mobile log:

When pressed:

Notice how the timestamp for the cancelled event appears to be wrong. All 3 log lines literally appear at the same time!

When released:

No change.


PS: It appears that this forum member has the same problem, no solution: New Input System: on-screen button release event trigger on mobile device (Android)

3 Likes

Hi,

I recently had the same issue, do you know if there’s any update on this?

1 Like

Hi there,

Same issue on my Android Nexus 5. I manually check the zero values to detect whether the player cancels the input action. A horrid decision with this =(

Please can you elaborate on this approach?

If I understand correctly, the phases are based on input values. I mean, when the system gets from an input device Zero, or Vector2.Zero, or Vector3.Zero values, the system interprets a phase of the event as the Cancel phase.

For example, you can see the code of the OnScreenButton script, provided with the InputSystem:

public void OnPointerUp(PointerEventData eventData)
{
    SendValueToControl(0.0f);
}

public void OnPointerDown(PointerEventData eventData)
{
    SendValueToControl(1.0f);
}

As you see, in OnPointerUp the script sends zero value.

You can check the value in the InputAction.CallbackContext for Zero:

private void OnAction(InputAction.CallbackContext context)
{
    // For buttons
    var button = context.ReadValue<float>();
    var isButtonCanceled = button == 0f;

    // Same for axis
    var axis = context.ReadValue<Vector2>();
    var isAxisCanceled = axis.sqrMagnitude == 0f;
}

I can’t guarantee that everything works that way 100%, but this approach does its job in my case.

In any case, I’m really looking forward to this problem being solved and everything will work normally.

1 Like

I’m not sure is this is your problem, but here are some things to know that worked for me.
Using input system 1.5.0

I was doing some quick tests here so I was using the PlayerInput component with the Send Messages behavior.

public void OnAttack(InputValue value)
{
    Debug.Log(value.Get());
    Debug.Log(value.GetType());
    Debug.Log(value.isPressed);
}

Under those conditions, if the inputActions ActionType is set to ‘Button’
It will only fire once, showing the log:
Output log when clicked

1
UnityEngine.InputSystem.InputValue
True

Changing the action type to Value fixed this and now its firing the pointerUp event:
Output log when clicked

1
UnityEngine.InputSystem.InputValue
True
Null
UnityEngine.InputSystem.InputValue
False

I didn’t compile a mobile version but at least in my editor with 2021.3.19f1 it was fixed.
The input system packaged has some very big changes each version, so maybe updating it
to the latest 1.5 might solve your issue.