In this week’s devblog let’s talk some more dev, in particular the Input system in Unity.

So far I’ve been using the default Input Manager that comes with Unity, but I got to a point where it just didn’t work anymore.

My main issue is that I want to support multiple input methods at once, namely keyboard, gamepad as well as VR controllers.

What I did so far was setup multiple virtual axis in the Input Manager, that meant I had one entry for each controller and axis and then I could just query for the axis “vertical” in code, which kinda works.

There are two problems with that however:

I might want to use different mappings in a different context. For example, to accelerate I use the trigger button on the vive controller and the right shoulder button on the xbox gamepad, but in the menu the trigger button is “confirm” which on the xbox gamepad would be the “A”-button.

That meant I had to setup a different virtual Axis for each context, for example “VerticalRace” and “VerticalMenu” which leads me to the second problem. Button mappings might clash between different controllers.

For example, “Button 0” on the vive controller is the Menu button, whereas on the xbox gamepad it’s the “A”-button, both of which I want to use for different actions. While Unity gives me the option to limit a virtual axis to a specific joystick there is, as far as I know, no real way to know whether the vive controller will be joystick 0, 1 or 42, which makes this virtually useless for this use case.

So what options are there?

Well, the good news is that Unity acknowledges the short comings of the current system and is working on a new system.

The bad news is, it’s still under heavy development and not stable yet. It’s current state is described as:

Feature Completeness: 80%

Stability/Robustness: 40%

Documentation: 10%

It’s expected to be fully ready by 2019.2, so some time in summer next year.

But there are very little serious alternatives that solve my problems and the new input system looks really promising, so I decided to give it a try.

First things first: Update your project to Unity 2018.3, I had only minor issues doing so but I was already on 2018.1 anyway.

Installing the new input manager and disabling the old is fairly straight forward as well, just follow the instructions on this github readme.

Now to the fun part, replacing everywhere in my code the old input system with the new one.

You’ll realise that they weren’t kidding when they said 10% documentation, luckily there are some examples to get you started on GitHub and the code is all in C# so you can check that.

What really helped me is that you can modify and debug the code just like your normal code so you can really check what’s going on.

It’s surely a bit more hands-on, but still easier than writing it yourself I suppose.

In the end I got it to work just fine with some minor issues as would be expected and I have to say I really quite like it:

The ActionReference assets are a really elegant way to overcome the context issue and the bindings are a fairly straight forward way to identify exactly what you need (however not all of them are working 100% yet, as you might expect, so hopefully there is still some work being done).

The main thing that still seems to be missing is an elegant and easy way to allow users rebinding keys at runtime, but I’m sure we’ll get there soon.