InputSystem icon indicating copy to clipboard operation
InputSystem copied to clipboard

Problems with dualshock 4 connected via bluetooth to Android device

Open fabiopicchi opened this issue 7 years ago • 6 comments

I have deployed my game to my own Android phone (moto g4) and the behaviour of the gamepad connected to it was very strange.

First of all, buttonWest (square) is mapped to buttonSouth (x) and buttonSouth is mapped to buttonEast (circle). Secondly, pressed, wasPressedThisFrame and wasReleasedThisFrame are acting in a very weird way. It seems that input is being activated on release and not on press but I haven't been able to confirm that.

Are gamepads currently supported on mobile platforms?

fabiopicchi avatar Jun 02 '19 17:06 fabiopicchi

I think the gamepads for Mobile platform is still under development. But Dualshock controller will be supported on Android once it is out of preview (1.0 release)

So about what motion fires "performed", the default is set to release. This is by design. However, you can change the Interactions property for the Action to change that. But by the sound of it, you want the "performed" get triggered by pressing down the button, correct? In that case, you want to add Press to Interaction, and set it to Press Only.

JiaUnity avatar Jun 14 '19 01:06 JiaUnity

Thanks for the reply @JiaUnity . Right now I am reading inputs directly from the device so I am not using the Action abstraction. This is mostly because, as of now, there is only an event based API for actions.

So I am reading the pressed boolean from a Gamepad object and not the performed event from an Action.

fabiopicchi avatar Jun 14 '19 08:06 fabiopicchi

Hey @fabiopicchi, thanks for the report, this is one tricky issue...

There's a comment left by the developer which explains the situation under: com.unity.inputsystem/InputSystem/Plugins/Android/AndroidGameController.cs

/// Some gamepads on Android devices (with same Android number version) might have different mappings
///  For ex., Dualshock, on NVidia Shield Console (OS 8.0) all buttons correctly map according to rules in AndroidGameControllerState
///           when clicking left shoulder it will go to AndroidKeyCode.ButtonL1, rightShoulder -> AndroidKeyCode.ButtonR1, etc
///           But, on Samsung Galaxy S9 (OS 8.0), the mapping is different
///           when clicking left shoulder it will go to AndroidKeyCode.ButtonY, rightShoulder -> AndroidKeyCode.ButtonZ, etc
///  So even though Android version is 8.0 in both cases, Dualshock will only correctly work on NVidia Shield Console
///  It's obvious that this depends on the driver and not Android OS, thus we can only assume Samsung in this case doesn't properly support Dualshock in their drivers
///  While we can do custom mapping for Samsung, we can never now when will they try to update the driver for Dualshock or some other gamepad

So since we don't have the power over OEMs and can't predict whether they support the controller or don't, and how well they support it there's not much we can do about it at the moment...

Current implementation uses mapping provided by Google, as can be seen under com.unity.inputsystem/InputSystem/Plugins/Android/AndroidKeyCode.cs (Google source: https://developer.android.com/reference/android/view/KeyEvent)

And they're supposed to be the correct ones IIRC Android 9 is the first version of android to officially support DualShock 4

@todi1856, do you have anything to add?

renaldasrep avatar Jun 14 '19 08:06 renaldasrep

Hmmm, this is weird because Motorola apparently is proud to say that it is using "pure Android" without any modifications. Anyway, all this gamepad/device/OS mappings are completely crazy, thanks a lot for your hard work in solving this issue :D

Maybe we could mantain a collaborative list of mappings per device/OS. I think the SDL community mantains something like that.

Anyway, is that somehow related to the pressed issue I mentioned?

fabiopicchi avatar Jun 14 '19 09:06 fabiopicchi

InputSystemMobile.zip

I'm using this project to test input on mobile, and I use latest version of Input System from the develop branch, here's the behaviour I'm getting:

File from iOS.m4v.zip (sorry for zip, can't upload video to GH)

Is it different for you? I can't reproduce what you're describing

renaldasrep avatar Jun 14 '19 09:06 renaldasrep

Since our QA has trouble repro this issue, and I don't have a good understanding how you wish to use ISX, I suggest upload a minimal repro project. You can also do this through Bug Reported in the Editor. This will help us to identify the issue better. Thanks!

JiaUnity avatar Jun 14 '19 16:06 JiaUnity