Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

New Input System randomly stops detecting keyboard input

Discussion in 'Input System' started by VascoRocha97, Apr 2, 2021.

  1. VascoRocha97

    VascoRocha97

    Joined:
    Jan 25, 2017
    Posts:
    7


    Hi everyone,
    I have this problem on my character controller, where the input from my keyboard randomly stops working and the capsule stops moving. The weird thing to me is that it works perfectly fine when i use a gamepad.
    I've monitored the input variables on the inspector and they just randomly go from 1 to 0.
    Any help is really appreciated.

    https://imgur.com/a/vwmlmyp
     
  2. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    661
    Where are you enabling your PlayerControls object?
     
  3. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    661
    Also, what are the Properties for your Movement action?

    When I run this code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Vasco : MonoBehaviour
    4. {
    5.     private void OnEnable()
    6.     {
    7.         var playerControls = new PlayerControls();
    8.         playerControls.Enable();
    9.         playerControls.PlayerMovement.Movement.performed +=
    10.             c => Debug.Log(c.ReadValue<Vector2>());
    11.     }
    12. }
    13.  
    I get this output for pushing w, a, s, d, w, a, s, and d:

    upload_2021-4-2_11-9-23.png

    Looks good, right? I have my Movement action Action Type set to "Value." If I change that "Pass Through," and push w, a, s, and d, I get this:

    upload_2021-4-2_11-11-22.png

    But that still makes sense as the non-zero values are from when the key goes down, and the zero values are al from when a key goes up.

    Does any of that help?
     
  4. VascoRocha97

    VascoRocha97

    Joined:
    Jan 25, 2017
    Posts:
    7
    I think i figured out what the problem is. Unity must be overriding the keyboard input with the joystick input from the controller, making the values go to 0 and the character stop. Because when i unplug the controller the keyboard works fine. Any idea on how to solve that?
     
    Haldamir92 and PepperPaige like this.
  5. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    661
    Hey, good catch and thanks for sharing that info. Will be helpful if when the same thing happens to me.

    Now, what to do about it...

    If you knew you were only going to use the keyboard, you might be able to disable the Left Stick binding with the ApplyBindingOverride method (set the new binding to an empty string).

    If you want the stick to remain available, but not send spurious zeros, I'd try adding an "Axis Deadzone" processor to your stick's bindings.

    Hope that helps.
     
  6. VascoRocha97

    VascoRocha97

    Joined:
    Jan 25, 2017
    Posts:
    7
    I already tried the deadzone processor yesterday and it didn't seem to work, i'll keep trying to find a solution and update this if i figure it out.
     
  7. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    661
    Do you mean it did not actually create a dead zone, or that creating a dead zone did not solve your problem?
     
  8. VascoRocha97

    VascoRocha97

    Joined:
    Jan 25, 2017
    Posts:
    7
    I tried using a stick deadzone processor and it did create the deadzone, but it didn't stop the controller from randomly sending the 0s. It might have been me using the wrong values on the deadzone processor parameters tho.
     
  9. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    164
    I'm experiencing something similar. I have a setup where I need to control horizontal movement and jumping. You can control using a gamepad (left joystick for movement, south button for jump), or you can control using keyboard (A+D for movement, Space for jump).

    However, if I suspend my Windows laptop while Unity Editor is running, then reading Space for jump input no longer works when I resume Windows again. Keys A+D still works. And GamePad also still works.
     
  10. VascoRocha97

    VascoRocha97

    Joined:
    Jan 25, 2017
    Posts:
    7
    Can you show us your code?
     
  11. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    164
    I don't have a small repro project yet, but we're using PlayerInput.onActionTriggered to get a C# callback whenever an input is triggered.
     
  12. rsaherron

    rsaherron

    Joined:
    May 17, 2019
    Posts:
    1
    I was having very similar symptoms (Input System would randomly just stop sending callbacks). When I opened up the input debugger, it was registering the key presses, but the callbacks were never being called in my script.

    Restarting Unity didn't help. Rebooting didn't help.

    I also discovered in the input debugger that there were 2 "users" in the input system and (by process of disabling Game Objects in the scene one at a time) discovered that I had accidentally attached another copy of my Input Action Asset to a different Game Object in the scene and that Unity was registering this other object as a 2nd player or "user", which was assigned all the input actions I was trying to capture.

    The rogue Action Asset was essentially intercepting the actions, preventing the callbacks from being called on the intended script. I don't know if that's your particular issue, but maybe it will help someone else who (like me) has spent hours pouring through forums, looking for a solution to this elusive problem.
     
  13. jacristi

    jacristi

    Joined:
    Oct 2, 2020
    Posts:
    1
    I just had a similar issue with a 2d game. On left/right movement with A/D if I pressed both at once, it would not detect the next input and only the second input would register. Realized the problem was that I had at some point, added a hold interaction to the A/D movement input. (Figured this out when realized arrow keys and controller scheme didn't have the same problem). Hope this is helpful to someone
     
  14. SwingWren

    SwingWren

    Joined:
    Mar 1, 2014
    Posts:
    23
    Okey maybe this helps someone as I had this same problem and managed to solve it. Tested in demo unity control scene and has the same issue.

    This only happens if you have changed the input system package default Deadzone Min to 0 for example. Even if using deadzone in all stick controls this 0 is still affecting the PlayerInput.

    To solve this simply change that default value Deadzone Min to 0.1 for example
     
  15. Mr-Jun

    Mr-Jun

    Joined:
    Jul 1, 2015
    Posts:
    9
    I ran into a similar issue where the controller seems to be overriding all inputs when plugged in (Playstation controller).
    One way to fix was to mask the control schemes manually, but could no longer auto-switch back dependent on which device is being pressed because it's masked...

    In the end I found a strange workaround that works by resetting the action whenever my character isn't moving.
    Probably not efficient at all, but now I can switch between KBM and gamepad depending on what's pressed.


    Code (CSharp):
    1.  
    2. public void InputAction_MovePerformed(InputAction.CallbackContext context)
    3.     {
    4.         _moveVelocity = Vector3.ClampMagnitude(context.ReadValue<Vector3>(), 1.0f);
    5.  
    6.        if (_moveVelocity.sqrMagnitude == 0)
    7.         {
    8.             // A workaround
    9.             context.action.Reset();
    10.         }
    11.     }
    12.  
     
  16. ICE-jdeacutis

    ICE-jdeacutis

    Joined:
    Mar 10, 2021
    Posts:
    9
    This does not work in my case, I have a X52 joystick with a throttle and sliders that are constantly emitting changing values even when physically not moving (+/- 1 analog increment). Deadzone's cant fix that because those types of inputs aren't sprung back to a particular resting position to deadzone, any position can be a resting position. I can see on the PlayerInput component the Joystick is fighting the keyboard to remain as the current control scheme while my joystick isn't being used. What's even more annoying is its giving exclusive focus to my joystick because it thinks the throttle is moving, but the throttle isn't bound to anything so it shouldn't be doing this behavior regardless.

    What's most infuriating is I don't want Unity to "switch control scheme/device" based on another device's input at all, I didn't ask for that behavior and actively breaks what I'm trying to do. I need to process keyboard and joystick input at the same time, not one or the other. This seems like a pretty big oversight in their design.
     
    Last edited: Nov 1, 2022
  17. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    I have these same issues, where a controller joystick is constantly sending callbacks even when the Vector2 value is zero. This causes mouse movement to stutter. If the controller stick is not being moved, I don't want to receive any data from it. Applying a deadzone does not fix the issue.
     
  18. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    631
    Exactly I have the same problem, Seems like gamepads especially Xinput is sending events and interfering mouse delta even if it is not in actual control scheme. Any fix to tip how to resolve that from unity team?
     
  19. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    On my "Look" input action, the action type was "Pass Through" and I changed it to "Value" which seems to have stopped the rogue gamepad input events on every frame. This issue was easily reproduceable for me using a wired PS4 controller.

    Unfortunately, I believe I had it set to "Pass Through" a while ago to fix the issue mentioned by the OP. Using Input System 1.4.1.

    upload_2022-11-22_9-49-36.png
     
  20. ClearRoseOfWar

    ClearRoseOfWar

    Joined:
    Sep 6, 2015
    Posts:
    87
    unfortunately for me, using passthrough seems to create a ton of error logs:

    upload_2023-1-6_13-25-54.png

    any ideas why?
     
  21. InquisitorTR

    InquisitorTR

    Joined:
    Nov 28, 2022
    Posts:
    1
    I have the same issue, I just need to use Gamepad but one of my agent is beginning with "Touch" device instead of "Gamepad". Others are okay but user2 that assign only that agent cause to distruption for that agent and I cant move it. It doesnt react to anyting. What should I do? All my agents have Player Input. Should I use only one Player Input in one common gameObject that all others agents can reach there?