Unity: default input on different platforms and my workaround

In Brazil we have a word that I don’t think we can inarguably decide the translation to english: gambiarra. It stands for a dirty workaround, something that works but may break at any moment and may be a pain to resolve. Well, a gambiarra is what I did to circumvent one of Unity’s input system problems.

After finishing RollFTW for the jam, I wanted to improve the input handling to support different platforms, other than desktops with keyboard, just for learning. I usually like to create a API that offers the buttons and axes from a XBOX gamepad, and then, depending on the platform, fetch these informations in specific ways, so I created a central static class to standardize that. However, when supporting the actual XBOX gamepad, my main problem arose:

In Unity’s Input Manager, you can’t set the default main button per platform.

Which is a bummer because the button mappings are pretty different between platforms (i.g. button A is joystick button 0 in Windows and joystick button 16 in OSX). I started doing something like this:

Code horror
Creepy!

I think you can imagine how these would be used. But, then, on a game that showed the default Unity configuration window, setting up the controls would be almost impossible for the player. I also don’t want to just leave the Windows configuration as default for all platforms, as I like to prevent the player from having to configure stuff as much as possible.

Enters my gambiarra: inside the project folder, I replicated the InputManager.asset file for each platform (Windows, Linux and OSX), and my build script would rename them as needed before compiling the game.

Input Manager replicated assets

You can see my full build script here (sorry, Windows users!):

A small note is that I needed to change the sensitivity of the axes to 3, not sure why. I guess this can be a OSX related issue.

Suggestions? Leave a comment below!

Leave a Reply

Your email address will not be published. Required fields are marked *