Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Controller wrongly characterized as joystick for input (Logitech Dual Action)

Discussion in 'Input System' started by kendallroth, Apr 29, 2020.

  1. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    Unity Version: 2019.3.11f1 Personal
    Input Manager: preview.7 - 1.0.0
    OS: Windows 10
    Controller: Logitech Dual Action

    I've been struggling with the new Unity Input System (and mostly enjoying it) for most of today as I try to get my Logitech Dual Action controllers to work with the system. I finally managed to get it responding after realizing that I needed to "listen" for the input in the Input Manager, which then assigned Joystick values instead of Gamepad values. This made me realize that the controller was being genericized as a joystick, not a gamepad as it should be. Per Unity's own documentation the controller has everything a gamepad should have; however, I wonder if it is not being conveyed properly from the joystick itself.

    While the controller does have the necessary pieces, they are not mapped to a gamepad (likely because Unity thinks its a joystick). Instead, the names used by Unity are shown in the sheet below.

    I've attached a sheet (and linked it here) showing the values that the Unity Analysis > Input Debugger shows for the controller itself. I'm assuming this data will be necessary for me if I want to write my own mapping (and maybe more?), but wondered if it would give anyone additional insight. For example, it shows "Rz" and "z" axis that should instead be the right stick on a gamepad. logitech_controller_problem.png
    What could maybe work is if I could somehow trick the input system or binding manager into using both the "Rz" and "z" axis in a single Vector2 somehow, so that it would appear the same as a joystick or dpad... But I haven't had any luck doing this yet...and this isn't actually a full solution.
    1. Does anyone have experience with this?
    2. Why is the controller being characterized as a joystick?
    3. How would I create my own mapping for the controller?
    4. Most importantly, what information would I need for that?
    I hope I've included everything necessary, but let me know if not!

    I also linked an asset package with my project, showing two bindings under the Cube action map for Gamepad, one with how I have to do it for Logitech (joystick...) and the other for normal gamepads.
     

    Attached Files:

    D_MAS likes this.
  2. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    So I was actually able to figure out the manual remapping process after taking a few hours of a break. I figured that if I didn't know what I was doing, I couldn't at least mess anything up worse! And lo and behold, it turns out that I didn't actually have to change almost anything from the scripts provided by Unity (although it is tricky to find them).

    The following link explains the process of creating an override mapping, although it leaves out the actual tutorial part... It turns out that the numbers () provided by the Analysis > Input Debugger are the numbers necessary for the override. In my case, they turned out to be the same as the existing ones in the example provided by Unity. It helped that during my hours away I exchanged a controller with a friend so that I had a PS4 controller to test with, which helped me realize this.
    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/HID.html

    Somewhere else I read that something characterized as a generic joystick will search for the first button and assign it as the trigger, which explains why "button1" (or "ButtonWest") was set as trigger. Additionally, it will look for the first x and y axis and set it as the joystick, which explains why the right stick was separated into two axis (since generic joystick only has a single stick).

    Here's the process for anyone else experiencing this:
    • Create a struct representing the input report (implements
      IInputStateTypeInfo
      )
    • Validate that the offsets and bits are correct in the annotations, etc.
    • Comment out any unnecessary buttons (if controller doesn't have them, just for cleaning it up)
    • Create an HID class (extends
      Gamepad
      ) and ensure it loads with Unity
    It turns out that this was rather easy actually, it's just not explained well on the Unity documentation (likely because it is a preview package)...
     

    Attached Files:

    ShokWayve, D_MAS, Sarai and 1 other person like this.
  3. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    Note that to get the two triggers working properly (so that they would be detected as regular gamepad input) I had to slightly edit a few lines where the "leftTriggerButton" and "rightTriggerButton" were previously defined, simply setting them to "leftTrigger" and "rightTrigger" respectively, as well as adding a
    format = "BIT"
    .

    Code (CSharp):
    1.  
    2.     //[InputControl(name = "leftTriggerButton", layout = "Button", bit = 2)]
    3.     //[InputControl(name = "rightTriggerButton", layout = "Button", bit = 3)]
    4.     // NOTE: These triggers need to be remapped from "trigger...Button" to "trigger..." to function properly as a gamepad
    5.     [InputControl(name = "leftTrigger", layout = "Button", bit = 2, format = "BIT")]
    6.     [InputControl(name = "rightTrigger", layout = "Button", bit = 3, format = "BIT")]
    7.  
    I kept the bottom stuff (where "rightTrigger" and "leftTrigger" were originally defined by the documentation) commented out, as I couldn't get it to work.
     
    D_MAS and UnCloak like this.
  4. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    So although everything is working as expected in the Editor, as soon as I try to make it work in a build the Logitech device is not recognized (although the PS4 controller works as expected if the build mode is set to
    x86_64
    ). Both devices show up in the Remote list but neither actually show any values, even though the PS4 controller works as expected...
     
    D_MAS and UnCloak like this.
  5. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    I did a few tests with the older Logitech Dual Actions ( as opposed to the F310 pad ) just the other day. They, of course, show up as HID Joystick, not gamepads, as the official gamepad list for the InputSystem is basically just the big console ones.

    Setting the build mode to x86_64 resolved the detection of the Dual Action for me just fine.

    I'll take another peak at this tomorrow to see if I can replicate the issue after defining it as a gamepad properly...

    Until then you can find me on Unity Discord (@AngryArugula) if you feel like chattin :)
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    I'll add something to the docs to make this more explicit.

    Basically, the rationale here is: Gamepad is meant to give a "hard" guarantee about its controls. The "buttonSouth" control, for example, is expected to be guaranteed to always be the bottom face button on the controller. With HIDs we don't specifically support we can't guarantee the mapping even if the device advertises itself as a gamepad. It'll just have a random assortment of button0, button1, button2, etc. controls. Even the stick and trigger axes follow no standardized pattern.

    This led to the decision to have generic HID gamepads come out as Joysticks -- which are basically the wild west in terms of button and axis configurations.

    There's definitely some downsides to doing it this way. Could be there's ways to improve this.

    Yup, this is currently the only way out. Overriding the HID fallback allows establishing the guaranteed mappings required by Gamepad. This is what we do ourselves, for example, for the PS4 controller.

    Yeah, like @Fenrisul mentions, this currently requires using a x86_x64 Windows player. For some reason we haven't looked into yet, the 32-bit player will not surface any HID input.
     
  7. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    @Fenrisul I am unsure about the model of my Logitech Dual Action controllers (is it on device?), although it's not the F310 and is probably similar to what you were testing. However, they are recognized in the Editor as gamepads (now that I have created the mapping above) but not in Builds (even for
    x86_64
    ). The PS4 is recognized in both, as long as the build is for
    x86_64 
    (this is acceptable for the moment, since I can test
    x64
    ).

    @Rene-Damm Thank you, this does make sense to me, especially once I read those docs and figured out that was why it was characterizing it as a joystick (the determination process you explained makes sense to me). Am I correct in saying that, with the mapping I created, the Input System should recognize the Logitech controllers as fulfilling the hard guarantee about gamepad controls (since it does work in the Editor)? Fairly certain that's what your second response was confirming, just was curious if you knew why it wasn't working in
    x86_64 
    builds. I would probably recommend a bit more explanation of what is happening (and how to find the mapping numbers) in the guide, but I completely understand that it's still in progress! Thanks for the work that has already been put into it!

    I've linked the built game project that I've been testing with the PS4 controller (works) and the Logitech controller (not recognized) if that helps.
     
  8. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    Worked the problem! It actually wasn't the HID descriptor @kendallroth wrote, it was PlayerInput handling things in a VERY strange fashion. I will make another thread and bug report.

    Attached a definition for Logitech Dual Action controller for anyone else to use.
     

    Attached Files:

    ShokWayve, InfinityXZero and D_MAS like this.
  9. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    Can confirm that it appears to be because I relied on the third type of
    PlayerInputManager
    join behaviour (ie. using preinstantiated characters). This resulted in a lot of strange behaviour and can be resolved by using one of the other two methods. It is strange behaviour (slightly undeterministic) but I wonder if the docs could be updated to point users to the other to methods as preferred?

    Thanks for the help @Fenrisul!
     
  10. Domarius

    Domarius

    Joined:
    Jan 5, 2013
    Posts:
    103
    @kendallroth Man, thanks for your existing work on this. And @Fenrisul thanks for your polished up InputReport. I also happen to have a Dual Action handy and was able to better understand what's going on by getting your files to work. Also I too, see that they don't work unless you compile for 64bit.

    But, we will have to make our own solution anyway, for unrecognised gamepads, which lets them map their controls and save that configuration text file under the name of that gamepad, so it'll load automatically next time. Using such a system, you can easily provide new text files as you discover new layouts from your users. And you can add them without making a new build.

    Yes there is! Judging from observation, poking around game data files, and reading on forums, it seems that every independent developer does their own collecting of "known button layouts" of popular gamepads, with varying degrees of completeness, and this seems like a lot of wasted effort when we could be pooling them into a central repository of known button layouts that all Unity developers could benefit from. The new Input System seems like the perfect opportunity to do this. Perhaps there's a way we could submit our own HIDInputReport files to Unity?
     
    Last edited: May 2, 2020
    Sinister-Design likes this.
  11. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    If it works correctly in the editor, should work in the player just fine.

    The idea of a repository where we crowd-source controller layouts has been floating around. Potentially with a tool to automatically create and submit those layouts for simple cases (which can be covered through a simple "now press buttonSouth" kind of process). Would be great to have this for both gamepads and joysticks.

    We wouldn't be able to sufficiently QA these layouts on our side so it'd likely be a separate package but still, I think it'd provide great value even if some layouts end up a little "suboptimal."
     
    Domarius likes this.
  12. Domarius

    Domarius

    Joined:
    Jan 5, 2013
    Posts:
    103
    That's good to know Rene-Damm, thanks :)
    That's exactly what I'm going to make for my game, to collect my own layouts from people :) Let me know if I can provide anything. Not that it's hard to do or anything, but it seems a lot of people would be re-duplicating this effort in some form so I'm all for pooling the efforts somehow.
     
  13. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    @Rene-Damm Unfortunately it was not working in the builds (if that is what you were referring to as "Player"), but solely the editor. I think this was the source of my confusion, as I couldn't figure out why (no matter what) it would only work in the editor. However, after providing the custom mapping and figuring out a few quirks with the PlayerInputManager, things seems to be working fine.

    I highly agree with the idea of crowd-sourced controller layouts. While they could likely never by officially QAed (as you mentioned), having the ability to indicate which ones work (via the community) could be a nice touch (albeit a little outside of a typical repository setup).
     
  14. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    I'd be down for helping lead a community-built database of devices. Developing XR peripherals and other input-type stuff professionally means I have a lot of random kit laying around - and I'm not scared of weird binary payloads.

    I've heard a lot of demand for well mapped Flight Stick, Throttle, Pedals, and Fight Pad/Sticks.

    Perhaps a simple application that captures WebCam input to a video (pointed at a gamepad/device), and a InputSystem log, packages it up, submits to web thing, would be ideal here. Capture process would be "Push each button for 1 second, wait 1 second, next button" etc. Thats about the only way I can think of arbitrarily (and uniformly) capturing and mapping a device's inputs. The one exception so far has been a flight control system some posted earlier that actually sends TWO HID reports instead of one... that broke all the things heh.
     
  15. Domarius

    Domarius

    Joined:
    Jan 5, 2013
    Posts:
    103
    I'd say you can skip the webcam step and make it far more likely that people will submit the layouts. I've seen people on forums happily giving out the button indexes for the standard "xbox layout" from their gamepads to help a developer out, and that's mostly what's needed.

    People just want to plug in what looks like a dual analogue controller, and have it behave as such. The "Gamepad" device in the new Input System already does this, it's just missing layouts for more USB gamepads.

    So all you need is a simple program that steps through each control "Press south button" "Press left thumbstick left" etc. with a diagram of a generic dual analogue, highlighting each control (letting you skip ones you don't have). That's what I'm making for my game - every gamepad driven game could the layouts created from this (like what's already built into SDL).

    If you want, you could do the same with a generic "FlightStick" and "SteeringWheel" concepts - they all have common conventions now with optional features. Layouts for them can be captured too. But just capturing gamepad layouts would solve 90% of cases.
     
    Last edited: May 9, 2020
  16. UncleAlias

    UncleAlias

    Joined:
    Aug 18, 2017
    Posts:
    27
    I know this thread is old, and you figured everything out, and you probably know this, but just in case: there's a switch on new Logitech Gamepads that switches between DirectInput (which I think Unity Input sees as a "Joystick") and XInput (which is the newer API Xbox controllers use). If there is no switch, then its probably an old, DirectInput only pad which will just not work on games that are expecting an Xbox controller, even though they look the same as the new ones.
     
  17. kendallroth

    kendallroth

    Joined:
    Nov 4, 2015
    Posts:
    20
    @UncleAlias I was not aware of that actually! However, I was able to resolve the issue by creating a custom mapping.
     
    UncleAlias likes this.
  18. Hysparions

    Hysparions

    Joined:
    Jan 7, 2019
    Posts:
    29
    Hello everyone, thanks for putting such efforts on this subject, it helped me to understand the way things work on Input System Layout. I have to Switch Wireless Gamepad which were not recognized has Gamepads but joysticks. I am trying to create my own Switch Controller layout but I have no clue of the organization of the data Inside this controller. I tried to use the one in the SwitchProControllerHIDInputState, but the input debugger clearly shows that the mapping is wrong.

    How did you find which byte represents which button / stick
     
  19. TheodorGal1977

    TheodorGal1977

    Joined:
    Feb 3, 2021
    Posts:
    10
    Big thanks to everyone in this post, as it greatly helped me to configure an old "Logic3" USB game controller as a gamepad. Will post my project for others in a new thread
     
  20. peewee1476

    peewee1476

    Joined:
    May 27, 2017
    Posts:
    8
    Is it possible to extrapolate on this further? I am also having this issue, currently with an Xbox controller, and I have done the x86_64 build thing to no avail. Forgive my ignorance, could you explain what you mean by the custom mapping? I thought the InputActions that I created for my Unity project WAS the custom mapping? Do you mean that you had to create a custom mapping for several controllers instead of using the generic inputs in the action maps? Thank you!

    Oh, I'm also running the following code to see my input, and I am getting input results in Editor and in the build:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class RecordControllerInput : MonoBehaviour {
    6.  
    7.     private string[] joystickNames;
    8.     private float xAxis, yAxis;
    9.     private List<string> lastPressedKeys = new List<string>();
    10.  
    11.     void Update () {
    12.         joystickNames = Input.GetJoystickNames();
    13.         xAxis = Input.GetAxis("Horizontal");
    14.         yAxis = Input.GetAxis("Vertical");
    15.  
    16.         foreach ( KeyCode curKey in Enum.GetValues(typeof(KeyCode)) )
    17.         {
    18.             if (Input.GetKeyDown(curKey))
    19.             {
    20.                 lastPressedKeys.Add(curKey.ToString());
    21.                 if (lastPressedKeys.Count > 10)
    22.                     lastPressedKeys.RemoveAt(0);
    23.             }
    24.         }
    25.     }
    26.  
    27.     private void OnGUI()
    28.     {
    29.         GUILayout.Label("Joysticks:");
    30.         foreach (var curName in joystickNames)
    31.             GUILayout.Label(string.Format("   {0}", curName));
    32.         GUILayout.Label(string.Format("Axes: ({0}, {1})", xAxis, yAxis));
    33.  
    34.         GUILayout.Label("Last pressed keys:");
    35.         foreach (var curKeyName in lastPressedKeys)
    36.             GUILayout.Label(string.Format("   {0}", curKeyName));
    37.     }
    38. }
     
  21. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    Sorry to necro an ancient thread but did anything come of this? I've recently come to a similar conclusion after dealing with an avalanche of irritated users and would obviously not rather re-invent the wheel. If not, does anyone have any idea how we could build a tool which would generate the data needed to create overrides?
     
    LongToothMedia and virtualjay like this.
  22. jackjansen

    jackjansen

    Joined:
    Apr 4, 2019
    Posts:
    22
    Here's a "me too" for @jukibom's request. Now that I finally found this thread at least I know what to do for the gamepad(ish) devices I have physical access to (thanks everyone in this thread!), but an open repository would be nice. That would also be a great place to record where specific devices have idiosyncrasies (such as my ancient Logitech Rumbled that has trigger buttons, not axes).
     
    LongToothMedia likes this.
  23. jeepcreep

    jeepcreep

    Joined:
    Oct 20, 2015
    Posts:
    7
    If anyone here is in need of the ActionInputReport struct for a Logitech Dualaction F-310 gamepad, I'd gladly post it here on demand... I've just worked out all the nitty-gritty details of that specific controller and now everything is working like a charm ;)
     
  24. Dehaku

    Dehaku

    Joined:
    Mar 8, 2021
    Posts:
    5
    Actually yes, I just noticed that when I use an InputAction variable in a script and add "Start [Gamepad]" with the previous mentioned modifications, the action no longer works. I'd love a working version.
     
  25. jeepcreep

    jeepcreep

    Joined:
    Oct 20, 2015
    Posts:
    7
    The attached files are actually everything that's needed to get the aforementioned Logitech GamePad working as a proper gamepad - and not as a joystick. One disclaimer though: all the buttons match correctly except for the leftStickPress and rightStickPress ones respectively... everything was done using the Input Debugger and working my way through the offsets and bits but these two I wasn't able to find after all, but then again: they're not *that* extensively used anyways in most games... all the other buttons work flawlessly.
    That HID class make sure everything is properly loaded into and initialized into Unity and from there you can basically just use it in InputActions of your InputSystem. Please make sure to give it a name of your liking so that you will spot the right controller, mine is called "Logitech Dual Action (Unofficial)" (see HID class) but that's just copy-pasted

    Have fun!
     

    Attached Files:

  26. D_MAS

    D_MAS

    Joined:
    Aug 28, 2019
    Posts:
    4
    helped me get my bootleg controller to stop being recognized as a "joystick" using both the Dual Action and PS4 .cs files as references, thanks
     

    Attached Files:

    ShokWayve likes this.
  27. AuroraUnit

    AuroraUnit

    Joined:
    Aug 7, 2013
    Posts:
    7
    I'm gonna revive this thread because I can't believe this issue has been persisting for 3 years and we're no closer to resolution.

    I'm using an 8BitDo Lite 2 controller and it also got read as a Joystick instead of a Gamepad. The attached files in this thread so far are for a Logitech device.

    Is there any investigation to allow developers to just change the device type in the Input Debugger against what Unity initially detected?

    Or at least, documenting this issue better in the documentation for the new input system along with how to resolve it instead of what's been presented in this thread so far specific to the Logitech device? The documentation has developers run around terms that only abstract the problem into "HID device" and "Custom Device Workflow" without presenting a base example that maps to a controller. The base example provided is limited because it only has a "firstButton", "secondButton", and "axis": https://docs.unity3d.com/Packages/c...nual/HID.html#creating-a-custom-device-layout

    This seems like basic stuff to accommodate player controllers and it's frustrating that the official solution seems to be bespoke workarounds for every third-party controller.
     
    Last edited: Nov 21, 2023
  28. InfinityXZero

    InfinityXZero

    Joined:
    Jan 6, 2022
    Posts:
    1
    You sir, are a legend. This works perfectly for me. Thank you.
     
  29. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    136
    How can I use this file? Do I need to attach it to a gameobjec for it to work?
     
  30. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    136
    THANK YOU!!!! This helped me a ton.
     
  31. ShokWayve

    ShokWayve

    Joined:
    Jan 16, 2013
    Posts:
    136
    THANKS!!! This helped me out a lot.
     
  32. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    Well it's been a while and I had a free weekend so I've made a start. Very much WIP but can at least query device binary data in a distributable package. Moving on to serialization and testing next.

    https://github.com/jukibom/unity-community-input-device-layouts
     
  33. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618