Search Unity

OnScreenButton is cancelled on Android while not moving finger

Discussion in 'Input System' started by Prolantis, Dec 3, 2020.

  1. Prolantis

    Prolantis

    Joined:
    Jan 17, 2016
    Posts:
    5
    I am using two OnScreenButton components to control a player. I want the player to move left/right when I hold the buttons and stop when I release them. It works in the editor, but on both iOS and Android I get "cancelled" events right after the first move event through my PlayerInput setup without releasing the buttons.








    Code (CSharp):
    1.  public class CharacterInputComponent : MonoBehaviour
    2.     {
    3.         [SerializeField] public CharacterMovementComponent movement;
    4.  
    5.         private bool _holding;
    6.  
    7.         // ReSharper disable once UnusedMember.Global
    8.         public void Move(InputAction.CallbackContext c)
    9.         {
    10.             if (c.started)
    11.             {
    12.                 Vector2 value = c.ReadValue<Vector2>();
    13.                 if (Math.Abs(value.x - 1f) < 0.1f)
    14.                 {
    15.                     Debug.Log("MoveRight()");
    16.                     movement.SetMoveRight();
    17.                 }
    18.                 else if (Math.Abs(value.x + 1f) < 0.1f)
    19.                 {
    20.                     Debug.Log("MoveLeft()");
    21.                     movement.SetMoveLeft();
    22.                 }
    23.             }
    24.             else
    25.             {
    26.                 if (c.canceled)
    27.                 {
    28.                     Debug.Log("StopMove()");
    29.                     movement.SetStopMove();
    30.                 }
    31.             }
    32.         }
    33.     }
    Is this a bug in the input system with touch? Or am I missing something?.
     
  2. Prolantis

    Prolantis

    Joined:
    Jan 17, 2016
    Posts:
    5
    https://forum.unity.com/threads/on-screen-button-holds-inadvertently-calling-cancel.998021/

    The forum won't let me add this link to my post when I Edit. So sorry for the spam, but this thread makes me believe this might be a bug and I am curious if somebody knows when and if this might be fixed. Or what I can do to solve this issue?

    Edit: this also describes the issue I am having and the process I am using.
    https://answers.unity.com/questions/1708967/input-system-on-screen-button-doesnt-work-with-tou.html
     
    Last edited: Dec 3, 2020