Search Unity

Bug InputAction's readValue returns values when it shouldn't

Discussion in 'Input System' started by toad02, Sep 18, 2020.

  1. toad02

    toad02

    Joined:
    Mar 7, 2014
    Posts:
    4
    Hi. I've been having this problem for a very long time and could find no solution so I come here looking for help.

    The problem is that occasionally my InputActions return values when no button is pressed. Sometimes for a brief moment only, barely noticeable (although you feel the controls feel weird and less responsible), but sometimes it appear to last until another input is registered. I used one of these opportunities to register a video of the problem happening:



    As you can see I print a value that indicates that my var movementBuffer.x = -1 but I am not pressing anything on my keyboard.
    The code running on this is actually very simple.
    A stripped down of this code version is:

    Code (CSharp):
    1. [DefaultExecutionOrder(-100)]
    2. public class CharacterInput : MonoBehaviour
    3. {
    4.   [HideInInspector] public float horizontal; //Float that stores horizontal input
    5.   [HideInInspector] public float vertical;
    6.  
    7.   InputAction movementAction;
    8.   private PlayerInput playerInput;
    9.   private Vector2 movementBuffer = Vector2.zero;
    10.  
    11.  
    12.   void Awake() {
    13.     playerInput = GetComponent<PlayerInput>();
    14.     movementAction = playerInput.actions.FindAction("Movement");
    15.   }
    16.  
    17.   void Update() {
    18.     movementBuffer = movementAction.ReadValue<Vector2>();
    19.  
    20.     if (movementBuffer.x != 0) {
    21.       print("movementBuffer.x " + movementBuffer.x);
    22.     }
    23.   }
    24.  
    25. }
    Some more info that might be helpful to find out the problem:





    Other observations:
    • This happens to other actions as well (I have a simple input buffer in place), but movement is coded exactly the way I show you in this code, very simple, as you can see, so it's what I have been using to debug this problem and the only thing I can get is that readValue returns something other than zero sometimes when it shouldn't.
    • This also happens using different input methods (keyboard or PS4 gamepad).
    • No gamepad was connected during the recording of the video. I made sure that nothing else was connected by checking input debugger. Only the keyboard, mouse and touchpad were detected and no actions are assigned to nothing else but keyboard and gamepad.
    • The problem only happens in the new input system. When I was using the old system the controls worked fine and I would go back, but I would like to try a bit longer since I like many of the new features.

    I'd really appreciate any help because I am really out of ideas here!
    Thanks!
     
  2. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    Are you on macOS by chance? I and a lot of other Mac users are having issues where if we CMD Tab back to Unity, or a build, the left input, if it's bound to 'A', will continue to register as pressed, even though it was never touched.
     
  3. Gronade

    Gronade

    Joined:
    Feb 14, 2020
    Posts:
    8
    Did you find a fix for this problem?