Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug [WORKAROUND] Controller sends input although no key pressed at startup

Discussion in 'Input System' started by JanBaaootbg, Jun 13, 2022.

  1. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    Hi,

    sometimes after I start my game (in Editor or Player) the avatar is moving from the get-go.
    After I pressed any button on the controller or slightly touched any analog stick the movement stops.
    I also experience this behavior after starting the game and then connecting the controller.

    I also get an input shown in the InputDebugger-Window (see file attached)

    Any idea what cases this issue or how to workaround it?
     

    Attached Files:

  2. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    No one faces similar issues?
     
  3. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    I do have now 3 repots from players and no other developer faced such issue, yet?
     
  4. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
  5. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Here's my current solution:

    I have:
    Code (CSharp):
    1.  
    2.         private float initialThrust;
    3.         private float initialYaw;
    4.         private float initialWing;
    5.         private float initialRudder;
    6.  
    7.         private float previousThrust = -1F;
    8.         private float previousYaw = 0F;
    9.         private float previousWing = 0F;
    10.         private float previousRudder = 0F;
    11.  
    vF
    each being the expected 0 actuation value

    in my init:
    Code (CSharp):
    1.  
    2.                 initialThrust = thrust_joy.ReadValue<float>();
    3.                 initialYaw = yaw_joy.ReadValue<float>();
    4.                 initialWing = wing_joy.ReadValue<float>();
    5.                 initialRudder = rudder_joy.ReadValue<float>();
    6.  
    X_joy
    being my controller's analog
    InputAction
    s

    in my gameplay update loop:
    Code (CSharp):
    1.  
    2.             float joy_rudder = rudder_joy.ReadValue<float>();
    3.             float joy_yaw = yaw_joy.ReadValue<float>();
    4.             float joy_wing = wing_joy.ReadValue<float>();
    5.             float joy_thrust = thrust_joy.ReadValue<float>();
    6.  
    7.             if(joy_thrust == initialThrust && joy_rudder == initialRudder && joy_yaw == initialYaw && joy_wing == initialWing)            // workaround Thrustmaster T1600.M / Windows / Unity readings before first input after program start bug
    8.             {
    9.                 joy_wing = previousWing;
    10.                 joy_yaw = previousYaw;
    11.                 joy_rudder = previousRudder;
    12.                 joy_thrust = previousThrust;
    13.             }
    14.  
    joy_Y
    being my quick access memory of the input values

    and at the end of that loop:
    Code (CSharp):
    1.  
    2.             previousThrust = joy_thrust;
    3.             previousRudder = joy_rudder;
    4.             previousYaw = joy_yaw;
    5.             previousWing = joy_wing;
    6.  
    so that when the player inputs the initial values by chance he does get a response albeit only "the closest approximation".


    Edit:

    Here'a set of values I got initially:
    t:1, r:-1, y:0,7506127, w:1


    and here's another from a different run of my program:
    t:1, r:-1, y:0,7800245, w:1


    t, r, y, w being thrust, rudder, yaw and wing input

    Expected values are:
    t:-1, r:0, y:0, w:0



    rudder = y-axis
    wing = x-axis
    yaw = z-rotation
    thrust = thrust slider
     
    Last edited: Jun 21, 2022
  6. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    Hi Unai,
    thanks for your repsonse.

    The observation you explained in the other post is 100% excatly my observation as well.
    I do have the issue with a Logitech Dual Action Gamepad but as far as I can verify, one player reporting this issue had only mouse and keyboard attached to the pc.
    The problem is, your workaround might doing fine with analog inputs but will fail with binary/keyboard input.
     
  7. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    i use InputAction s returning a float (0F/1F) for keyboard keys as well but didn‘t observe initialisation issues for them yet. Otoh filtering an initial 1F (and using a previous 0F) is no use, right.

    I observed actuating 1 analog input was sufficient to have all values be delivered correctly if i remember correctly now. Perhaps you can make a player have to press a single keyboard key at the beginning of your program to get values be delivered correctly
     
  8. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    Sadly, according to that specific player, pressing a key did not solve the issue ...

    The old input system had a ResetInputAxis method which might be suitable for this purpose ... unfortunately the new input system does not come up with a similar method.
     
  9. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    If you are „lucky“ the players report might be a coincidence: i had bluetooth keyboards which sometimes result in around 30 letters in text applications for a single keypress and other annoyances. Perhaps he is only using a Bt keyboard.
     
  10. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    In the meantime ... can someone of the unity team working on the new input system make a statement?
     
  11. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Today evening, for the first time ever, the joysticks trigger (digital) is now delivering a 1 after initialisation instead of 0 and 1 only when triggered physically.
     
  12. Unity-Artcraft

    Unity-Artcraft

    Joined:
    Jul 28, 2018
    Posts:
    85
    Last edited: Jun 26, 2022
  13. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    I've just created a bug report.
    I actually can't figure out how to make it public visible.
    The Id is IN-8494
     
    Unity-Artcraft likes this.
  14. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    I've found a pretty simple workaround!

    UnityEngine.InputSystem.InputSystem has a static method ResetDevice which did the trick.
    In my case a Logitech Dual Action caused the issue so I used Joystick.current as paramter.

    Code (CSharp):
    1. public class TestInput : MonoBehaviour, NewControls.INewactionmapActions
    2. {
    3.     private void Start()
    4.     {
    5.         var input = new NewControls();
    6.         input.Newactionmap.SetCallbacks(this);
    7.  
    8.         input.Enable();
    9.     }
    10.  
    11.     private bool _ghostInputHandled;
    12.  
    13.     void NewControls.INewactionmapActions.OnNewaction(InputAction.CallbackContext context)
    14.     {
    15.         if (!context.performed)
    16.             return;
    17.  
    18.         if (!_ghostInputHandled)
    19.         {
    20.             _ghostInputHandled = true;
    21.  
    22.             InputSystem.ResetDevice(Joystick.current);
    23.         }
    24.  
    25.         Debug.Log(context.ReadValue<Vector2>());
    26.     }
    27. }
    I attached a sample project for those facing the same issue.
     

    Attached Files:

    uani likes this.
  15. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Awesome!
     
  16. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    I now applied
    ResetDevice
    and it works for every
    InputAction
    like analogue axis and digital buttons in the limited testing I've performed over the last hour except for
    noisy
    controls like thrust slider which always send a value (note I pass
    true
    as argument 2 to
    ResetDevice
    ). Theirs initial value does not represent the state they actually are in and the observations detailed in my thread linked above (reply #3) still apply. As any action can be delivered by a thrust slider (when the player configures his input that way) I still have to perform a comparison with the initial value.
     
  17. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Btw folks, I would really appreciate if some of you could record the USB packet sequence with usblyzer or a similar low-level USB debugging tool. I recon the gamepad is not sending full state on connection and we instead mis-read some other packet as a state packet and get in a wrong state until controls are actuated. But I can't repro it locally right now.
     
  18. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    hi, thanks for tuning in. I used https://freeusbanalyzer.com/ . Attached a log of the T.16000M. After a Win 11 restart I didn't touch the device, everything in rest, thrust slider at minimum (should be value -1). I started the game, let it run for about 20 seconds then moved the x-axis of device to left, then to rest again, afterwards the thrust slider fully up and down again.
     

    Attached Files:

    • usb.zip
      File size:
      24.5 KB
      Views:
      152
    dmytro_at_unity likes this.
  19. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    @uani thanks a lot! So I see the first one with state payload is:
    Code (csharp):
    1.  
    2. 9    0x00000000    0    $print instruction         Direction    "Up"    04.07.2022 21:27:36
    3. 9    0x00000000    137    URB         urb    {}    04.07.2022 21:27:36
    4. 9    0x00000000    24    URB_HEADER         UrbHeader    {}    04.07.2022 21:27:36
    5. 9    0x00000000    2    unsigned short         Length    128    04.07.2022 21:27:36
    6. 9    0x00000002    2    URB_FUNCTION          Function    URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (9)    04.07.2022 21:27:36
    7. 9    0x00000004    4    USBD_STATUS           Status    { Status=SUCCESS (0); Type="Success" }    04.07.2022 21:27:36
    8. 9    0x00000004    4    StatusCode           Status    SUCCESS (0)    04.07.2022 21:27:36
    9. 9    0x00000008    0    $print instruction            Type    "Success"    04.07.2022 21:27:36
    10. 9    0x00000008    8    unsigned __int64            UsbdDeviceHandle    32393359252536    04.07.2022 21:27:36
    11. 9    0x00000010    8    unsigned __int64             UsbdFlags    0    04.07.2022 21:27:36
    12. 9    0x00000018    113    URB_BULK_OR_INTERRUPT_TRANSFER          BulkOrInterrupt    { PipeHandle=0xffffe289d60984f0; TransferFlags=DirectionIn | ShortTransferOk (3); TransferBufferLength=9; TransferBuffer=0xffffe289d5fbc190; TransferBufferMDL=0}    04.07.2022 21:27:36
    13. 9    0x00000018    8    unsigned __int64          PipeHandle    0xffffe289d60984f0    04.07.2022 21:27:36
    14. 9    0x00000020    4    USBD_TRANSFER_FLAGS           TransferFlags    DirectionIn | ShortTransferOk (3)    04.07.2022 21:27:36
    15. 9    0x00000024    4    unsigned long            TransferBufferLength    9    04.07.2022 21:27:36
    16. 9    0x00000028    8    unsigned __int64             TransferBuffer    0xffffe289d5fbc190    04.07.2022 21:27:36
    17. 9    0x00000030    8    unsigned __int64              TransferBufferMDL    0    04.07.2022 21:27:36
    18. 9    0x00000038    8    unsigned __int64               UrbLink    0    04.07.2022 21:27:36
    19. 9    0x00000040    64    URB_HCD_AREA                hca    { Reserved8={ 0, 0, 0, 0, 0} }    04.07.2022 21:27:36
    20. 9    0x00000040    64    unsigned __int64[8]                Reserved8    { 0, 0, 0, 0, 0}    04.07.2022 21:27:36
    21.                         00000000   0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000
    22. 9    0x00000080    9    UsbPayload                 Payload    { Payload={ 0, 0, 63, 46, 31} }    04.07.2022 21:27:36
    23. 9    0x00000080    9    unsigned char[9]                 Payload    { 0, 0, 63, 46, 31}    04.07.2022 21:27:36
    24.                         00000000   00 00 3f 2e 1f 00 20 80 e8                         ..?... ..
    25.  
    Unfortunately payload bytes are trimmed, could you check what the first payloads contain, and send the full descriptor if possible (first few frames), maybe I could compare it against HID descriptor and see if the payload is sound against the descriptor.

    After that would be nice to get raw hex bytes from first payload that you see in Unity (Window -> Analysis -> Input Debugger -> Double click on device -> Double click on first event -> Press see raw hex) so we could at least compare first packet that we see in managed code against packets on the wire.

    Thanks a lot!
     
  20. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    Hi,

    before logging I didn't disable my workaround code.

    Now I have and the issue doesn't occur anymore. I even uninstalled Free USB Analyzer = HHD Device Monitoring Studio, the issue still doesn't occur anymore.

    Note the issue occurred before the first input from the device: the data reported from
    ReadValue()
    was "wrong" before 1st device usage. As soon as the device is used all data gotten by
    ReadValue()
    is as expected.

    I have no clue why the issue doesn't occur anymore. (I mean i guess the type of drivers installed by above software and Wireshark which i also tried could have caused this but i uninstalled these and I hope they cleaned all remnants of them)
     
    dmytro_at_unity likes this.
  21. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    Hi,

    I tried to record some data via usblyzer ... unfortunately the issue does not occur anymore since installing usblyzer.
    After I deinstalled the tool, and rebooting the machine, still the issue does not occur anymore.

    On one hand it is good the issue is gone, on the other hand I don’t want to advice the players of my game to install usblyzer.
    Any idea what may have caused the issue to disappear? Might the advice to install the latest mainboard / USB drivers be the key?
     
  22. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
  23. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    I just answered my own question … unfortunately v1.4.1 did not solve the issue.

    In the meantime my bug report was closed due to “not qualified”…


    How can this be? In the first few days my demo was live two players reported the control bug … luckily, I found a workaround.

    Now the game is out, I have another report of the exact same issue although the workaround is in place.

    Ether those where the very few people on earth that had this issue, which is highly unlikely, or Unity will face huge problems in the future if the old input system gets deprecated and more games with the new input system will be released.


    Anyways, this needs to be fixed! I am willing to help finding the issue, although as I wrote some post ago, the issue will not appear anymore since I’ve installed usblyzer, but unity needs to show some initiative.

    It is surreal to close a bug report with the comment “[…] If you happen to find some steps or a project which reproduces this issue consistently, please reply […]” although I’ve attached a project along with instructions how to reproduce the issue.
     
  24. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    I just had an utterly fruitless conversation with the unity QA about the bug report I started about a month ago.
    Long story short, not only I have to come up with a project that makes the issue reproduceable … no! I need to come up with project that makes the issue reproduceable FOR THEM. Which is simply ridiculous …

    As if I had the time and hardware to play through a different thousand system combinations to finally find one that suits unity QAs needs.

    I’m done with this issue and will stick to my workaround …


    I always thought the reports from other unity users complaining about the impudence of unity to abuse its users as outsourced, nonpaid beta testers/QA were pushed a little too hard … until now.
     
  25. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    17
    After some further investigation with a player we figured out that vJoy was causing the issue.
    After disabeling vJoy the issue was gone entirely.
     
  26. uani

    uani

    Joined:
    Sep 6, 2013
    Posts:
    232
    vJoy could also be doing some driver configuration / reset (on disabling vJoy) same like usb analyzers did which Windows (11) (developers) failed to program and Unity doesn‘t (thus not expecting such failure) cater for resulting in the observed behavior.
     
  27. muhammad_ali_safdar

    muhammad_ali_safdar

    Joined:
    Jan 7, 2015
    Posts:
    15
    still issue in 1.5.1 .. testing with xbox one controller ...