Unity Custom Keybinding Manager

September 29, 2020

Unity

Keybinding Manager


Title: How to Create a Custom Keybinding Handler for your Unity Game – *Improved*
By: Dapper Dino
Youtube – Tutorial
Description: Tutorial for setting up an input manager scriptable object in Unity.


Overview

I was looking for a nicer way to control inputs and controls when setting up a Unity project other than the very basic way of listing out all the specific key codes in the user scripts themselves or using fragile string references when tying it to Unity’s natural input manager. Initially I came across this creator’s first attempt at setting up a keybinding handler (hence the *Improved* tag on the title of this tutorial) but was not as interested in it since they still used strings and I thought an enum implementation would be better, but lo and behold, the same creator had actually improved their system a year later with an enum system like I was imagining.

While maybe not perfect, I do still like this overall implementation better than just using Unity’s natural tools for sure. Adding the enum setup removes the necessity of typing in direct and exact strings in your code which is great for reliability, while also making it easy to change key bindings in the scriptable object itself during develop. Having a system like this is also a good start for a truly accessible product on release that allows users to set their own keybindings, which is standard in many games.