I’m building an arcade machine running in a NanoPI M4 (Android 8.1).
I have a custom-built USB controller, which I tried connecting to a Linux PC, a Windows PC and Android NanoPI and proved that is correctly recognized as a joystick by all of them.
I have a Unity project that simply shows which button was pressed, using roughly this code:
string s = "Buttons: ";
foreach (KeyCode k in Enum.GetValues(typeof(KeyCode))) {
if (Input.GetKey(k)) {
s += k.ToString() + " ";
}
}
GUI.Label(Screen.safeArea, s);
When I run it in Windows, I press the “first” button in the controller and I get as expected:
Buttons: JoystickButton0 Joystick1Button0
Same project built for Android, running in NanoPI M4, same controller connected to the USB port, I get:
Buttons: JoystickButton15 Joystick1Button15
I tried using a (generic, chinese) USB gamepad and got the same results: it seems that Unity in Android maps buttons 0-4 to 15-19; and any other buttons are not mapped at all!
This is the Android app Gamepad Tester showing that I am pressing the first button (to show that the OS is correctly recognizing the USB controller, and it’s Unity the one apparently messing things up):
And this is my simple Unity project running in the same Android box, same USB controller, same button:
Has anyone encountered the same behavior? Is there a way to instruct Unity to map the buttons differently?
Thanks!