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. Dismiss Notice

Question Gamepad controls on mobile are detected even if pad is not connected. This occurs only on 2 devices.

Discussion in 'Scripting' started by infernkp, Nov 12, 2021.

  1. infernkp

    infernkp

    Joined:
    Nov 25, 2020
    Posts:
    21
    This is how I am checking if gamepad is detected:
    Code (CSharp):
    1.     string[] temp = Input.GetJoystickNames();
    2.             obj.SetActive(false);
    3.             if (temp.Length > 0)
    4.             {
    5.                 for (int i = 0; i < temp.Length; ++i)
    6.                 {
    7.                     if (!string.IsNullOrEmpty(temp[i]))
    8.                     {
    9.                         if (!gamepadConnected)
    10.                         {
    11.                             gamepadID = i;
    12.                             ActivateGamePadControls();
    13.                         }
    14.                     }
    15.                     else
    16.                     {
    17.                   if (gamepadID == i && gamepadConnected) DeactivateGamePadControls();
    18.  
    19.                     }
    20.                 }
    21.             }

    I have no idea why gamepad controls are activated when gamepad is not even connected. This happens only on two devices tested (Android Redmi note 8t and Redmi 9), on other phones like S6,S7 (total about 12 devices tested) everything works just fine.

    What could be causing this?
     
    gsaurus likes this.
  2. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    Did you ever find a solution to this?

    I know this is an old thread but we experienced the exact same issue with the following Xiaomi Android devices:
    - Xiaomi Redmi Note 10 Pro
    - Xiaomi Redmi Note 12

    For some reason Unity is seeing this device as a gamepad. I had to remove the gamepad check because of these devices in order for it to work properly.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    What's the name of the gamepad it's reporting?

    Maybe something about these phone's feature set are implemented as a gamepad. If so, not a whole lot Unity would be able to do about it. But if the name's are consistent... you could filter them out.

    Also the name might hint at what that feature is.
     
  4. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    I'm not sure what it's reporting because it was from a hired tester. Is there a way for me to find out through logs that they can send over? The test is on a Closed Testing track on Android.
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    You'd have to have code that explicitly prints out the names to a log file, or on screen, or wherever you'd want them.

    Back when I wrote my cross platform input system I just created a project I called "InputSystemTester" and deployed it to all my platforms in question. On start it'd print on screen all devices attached and it'd report any button presses as you pressed them. I used this to figure out what various 3rd party controllers mapped as on different platforms.
     
  6. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    Thanks for the advice, I'll look into that.
     
  7. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    For anyone else experiencing issues with Xiaomi phones, my personal solution was to filter out devices that contain "uinput" in either the device display name or device product description as follows:

    Code (CSharp):
    1. if (device.displayName.Contains("uinput") || device.description.product.Contains("uinput"))
    2.      gamepadConnected = false;
    It appears that certain Xiaomi phones are recognized as gamepads. So check to see if it is a Gamepad and if so, filter out the ones with "uinput" since those are the devices that seem to have the issue.
     
    Last edited: Jul 10, 2023
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    What was the full name?

    Why uinput?

    (I get that uinput is in the full name... I'm just suggesting the full name would help other people better assess WHY uinput is a good word to match on versus something else)
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    Also, how sure are we that there are no legit gamepads that contain "uinput" in what they report as their name?
     
  10. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    "uinput-goodix" however, there were other cases online with these specific phones where uinput-* was troublesome as well.
     
  11. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    That's a fair concern, but for my use specifically, I'm relying on inputs that contain "gamepad" specifically so the use case can be different for others. I'm only stating what worked for me.
     
    AcidArrow likes this.
  12. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    So looking up uinput reveals that it could be related to the linux kernel uinput module used for emulating input devices:
    https://kernel.org/doc/html/v4.12/input/uinput.html

    The goodix likely relates to the goodix technology company in Shenzhen who designs things like touchscreens.

    You're probably picking up the touch screen's driver which relies on this module in the linux kernel in Android to do its stuff. Your approach could block out any emulated input device.

    This could rule out any android programs that perform a system wide overlay for a onscreen gamepad. These usually aren't official and instead require rooted devices, so not so much an issue.

    This could also impact any input devices that have specialized drivers that tap into uinput. Though I suspect those are far and between and could also run into rooting issues, so likely won't appear.

    ...

    So, I'd suspect blocking out uinput may not hurt user experience all that much. Though just be aware that if any complaints come in that their 3rd party weirdo controller doesn't work that this might be the first spot to look and check if that's how that gamepad implements it.
     
  13. ejoflo

    ejoflo

    Joined:
    Sep 15, 2021
    Posts:
    39
    Thanks for the additional information, definitely helpful!