Search Unity

Bug with two keyboard keys pressed or released simultaneously

Discussion in 'Input System' started by Zexar98, Mar 19, 2022.

  1. Zexar98

    Zexar98

    Joined:
    Apr 4, 2019
    Posts:
    5
    Bug with two keyboard keys pressed or released simultaneously - Unity Forum

    I have the same problem (sorry for my bad english, i am spanish).

    Unity 2021.2.12f1
    Input System 1.3.0

    In a 2D game with URP, i have 2 movement buttons (move left / move right). In adittion Jump, Dash, Attack.
    So I have a player controller script (in a Prefab with rigibody2d, sprite renderer, etc):

    private PlayerInputSystem playerInput; //Input System//
    private InputAction inputSlide, inputJump, inputAttack, inputMove;

    private void Awake() => playerInput = new PlayerInputSystem();

    private void OnEnable()
    {
    //Enable controls//
    inputSlide = playerInput.Player.Slide;
    inputSlide.Enable();
    inputSlide.performed += OnSlide;

    inputJump = playerInput.Player.Jump;
    inputJump.Enable();
    inputJump.performed += OnJump;
    inputJump.canceled += OnJump;

    inputAttack = playerInput.Player.Attack;
    inputAttack.Enable();
    inputAttack.performed += OnAttack;

    inputMove = playerInput.Player.Move;
    inputMove.Enable();
    }

    private void OnDisable()
    {
    //Disable controls//
    inputSlide.Disable();

    inputJump.Disable();

    inputAttack.Disable();

    inputMove.Disable();
    }

    private void Update() => horizontalMove = inputMove.ReadValue<float>();

    FixedUpdate { here rigidbody.Movement = horizontalMove and more code... }

    private void OnSlide(InputAction.CallbackContext ctx)
    {
    //logic//
    }

    private void OnAttack(InputAction.CallbackContext ctx)
    {
    //logic//
    }

    private void OnJump(InputAction.CallbackContext ctx)
    {
    //logic//
    }

    ------------------------------------------------------------------------
    In Unity editor work as expected, but when i am going to generate release apk (LZ4HC compression method, net framework 4, il2cpp) and i am going to install to my personal android mobile, is not working as expected (as Unity editor).
    If i Move Right and Move Left, in some cases canceled event is not executing (keeps performed phase).

    If I change/reload scene with the same Prefab Player (enable/disable controls), player prebaf sometimes starts jumping, dashing or attacking (i think it is the same as movement case -> composite binding, simple button, etc. I think Input System has a internal bug in android).
    If i am going to next level, when i am going to move right, and I am going to up my finger, player move lefts (because input system continues executing move left from other scene. Input System keeps phase i think, so move.disable() i s not working as expected i think).

    In editor no problems, only in android generated apk.

    My input actions:
    Move Value Axis -> 1D Axis with Left/Right arrow (Negative/Positive)
    Jump button Z (initial state check false)
    Attack button X (initial state check false)
    Dash button C (initial state check false)

    No processors/Interactions
    In canvas using On-Screen Button (Input System Script). If I press in Unity editor with mouse or keyboard key works as expected

    Input System is life for me, but in this state is unusable for me