October 14, 2020
Rebinding Keys
Unity – New Input System
Overview
I have been trying out the new Unity input system to see if it is worth using instead of the older method of building out everything yourself. In this process I wanted to make sure it had a way to rebind keys since this is a gigantic feature to have in almost all games. I was able to find that there are several different ways to change keybindings with the methods found in Unity’s documentation on the new input system found here: Unity Editing Keybindings for New Input System Version 1.0
The two main methods I am focused on currently are ApplyBindingOverride and PerformInteractiveRebinding. PerformInteractiveRebinding allows for keybinding modification by the player at runtime, and is a quick way to implement a feature commonly found in many games where the player selects an action to change the keybinding for and the game awaits their input to set the new keybinding to that input. I do not think this change is saved inherently however, which is where the other method comes in.
ApplyBindingOverride allows the system to override the default keybinds set by the game originally. So after using PerformInteractiveRebinding methods, that data can be saved to then later be utilized by the ApplyBindingOverride method to reapply the keybind changes every time the game is started. This helps it fall in line with how the feature is utilized in most games in a very convenient and user-friendly way.