Search Unity

[iOS] [2019.3.4] + bluetooth gamepad, no/broken Horizontal axis

Discussion in 'iOS and tvOS' started by Abatuf, Mar 19, 2020.

  1. Abatuf

    Abatuf

    Joined:
    Jan 9, 2014
    Posts:
    18
    iOS 13+, 2019.3.4, 2019.3.5
    Empty project, 2D template, no New Input System or anything else.

    Connected DS4(also tried with Nimbus) via Bluetooth to iOS device(iPhone XR and iPad Pro 2018). Unity Input does not react to Horizontal("X Axis") which represents Left Stick Left/Right positions. Pressing the Share button on DS4 sets Horizontal Axis to 1.

    Iterating all available axis(1 to 28) shows no presence of Left Stick Left/Right axis within them.

    2019.2.0 was fine.
     
  2. JBPrime

    JBPrime

    Joined:
    Jan 28, 2013
    Posts:
    6
    I discovered this is still happening in Unity 2019.3.11f1. I did find a workaround, but it's annoying to set up. You need to change code in iPhone_Sensors.mm, which is Unity's Objective-C code for interfacing with the Apple GameController system. Once you've built your Unity project into an Xcode project, open it up in Xcode and look for Classes -> iPhone_Sensors.mm. In this file, find the function:
    Code (CSharp):
    1. static void ReportJoystickExtended(int idx, GCExtendedGamepad* gamepad)
    At the end of this function, find this code block:
    Code (CSharp):
    1. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13.0)
    2. {
    3.     ReportJoystickButton(idx, BTN_MENU, [gamepad valueForKey: @"buttonMenu"]);
    4.     ReportJoystickButton(idx, BTN_PAUSE, [gamepad valueForKey: @"buttonOptions"]);
    5. }
    Change it to:
    Code (CSharp):
    1. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13.0)
    2. {
    3.     ReportJoystickButton(idx, BTN_MENU, [gamepad valueForKey: @"buttonMenu"]);
    4.     SetJoystickButtonState(idx + 1, BTN_PAUSE, GetButtonPressed([gamepad valueForKey: @"buttonOptions"]));
    5. }
    Be aware that when you make another Unity build (especially if you replace instead of append the Xcode project), this change will be erased and you'll have to do it again.

    As far as I can tell, it looks like the function ReportJoystickButton() both sets a button value and an analog stick value (which is generally okay). But BTN_PAUSE has a value of 0 (which is the correct button value), and that overwrites the actual value of axis 0, which is the left analog stick x-axis. I have submitted a bug to Unity.
     
    protopop likes this.
  3. virgilcwyile

    virgilcwyile

    Joined:
    Jan 31, 2016
    Posts:
    73
    I encountered exact same behaviour. I upgraded project to 2019.3.7 and Horizontal is broken now. Irony is it works perfectly in another game which was build using same version. I will try to use your fix
     
  4. virgilcwyile

    virgilcwyile

    Joined:
    Jan 31, 2016
    Posts:
    73
    Code (CSharp):
    1. static void ReportJoystickExtended(int idx, GCExtendedGamepad* gamepad)
    2. {
    3.     GCControllerDirectionPad* dpad = [gamepad dpad];
    4.     GCControllerDirectionPad* leftStick = [gamepad leftThumbstick];
    5.     GCControllerDirectionPad* rightStick = [gamepad rightThumbstick];
    6.  
    7.     UnitySetJoystickPosition(idx + 1, 0, GetAxisValue([leftStick xAxis]));
    8.     UnitySetJoystickPosition(idx + 1, 1, -GetAxisValue([leftStick yAxis]));
    9.  
    10.     UnitySetJoystickPosition(idx + 1, 2, GetAxisValue([rightStick xAxis]));
    11.     UnitySetJoystickPosition(idx + 1, 3, -GetAxisValue([rightStick yAxis]));
    12.     ReportJoystickButton(idx, BTN_DPAD_UP, [dpad up]);
    13.     ReportJoystickButton(idx, BTN_DPAD_RIGHT, [dpad right]);
    14.     ReportJoystickButton(idx, BTN_DPAD_DOWN, [dpad down]);
    15.     ReportJoystickButton(idx, BTN_DPAD_LEFT, [dpad left]);
    16.  
    17.     ReportJoystickButton(idx, BTN_A, [gamepad buttonA]);
    18.     ReportJoystickButton(idx, BTN_B, [gamepad buttonB]);
    19.     ReportJoystickButton(idx, BTN_Y, [gamepad buttonY]);
    20.     ReportJoystickButton(idx, BTN_X, [gamepad buttonX]);
    21.  
    22.     ReportJoystickButton(idx, BTN_L1, [gamepad leftShoulder]);
    23.     ReportJoystickButton(idx, BTN_R1, [gamepad rightShoulder]);
    24.     ReportJoystickButton(idx, BTN_L2, [gamepad leftTrigger]);
    25.     ReportJoystickButton(idx, BTN_R2, [gamepad rightTrigger]);
    26. }
    This is the code from the game which was build using Unity and which worked fine. I replaced this function with the game in which Horizontal was broken. So it worked fine. Unity might need to fix this.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,755
    Glad to hear this being broken on iOS and also broken on tvOS didn't stop Unity from releasing AN LTS version 4 months later.

    Apparently being unable to build something working for tvOS and support controllers on iOS WAS NOT A BLOCKER FOR AN LTS VERSION.

    And here they are talking about how they are dedicated to Quality : https://www.gamesindustry.biz/artic...-solutions-to-gamings-massive-content-problem

    WHAT A JOKE.
     
  6. geretti

    geretti

    Joined:
    Dec 20, 2016
    Posts:
    11
    This issue just started happening for us too. We were on 2018.4.11f1, which was working, and upgraded to 2018.4.23f1, which is not.
     
  7. aresundnes

    aresundnes

    Joined:
    Apr 29, 2013
    Posts:
    10
    Had this issue too with Unity 2018.4.23f, the fix from JBPrime worked for me.