Newer Unity Input System

October 5, 2020

Unity

Input Systems


Title: NEW INPUT SYSTEM in Unity
By: Brackeys
Youtube – Tutorial
Description: Tutorial for using Unity’s newer input system.


Overview

This setup uses Unity’s improved new input setup system. It provides a nice way to setup your inputs more specifically without directly going into the Project Settings -> Input Manager window. The user starts with a blank slate and adds actions to this input manager asset to match up with all the actions they will want in the game.

From this tutorial they obtained the tools to use this new input system through a project on github, but now it is available as a standard package within Unity simply named Input System. It however mentions that the backend has been modified (I am using Unity version 2020.1.5f1 currently when testing this) so I am keeping an eye out for any problems it may cause.

Tutorial Notes

There are three major sections to this input system: Action Maps, Actions, and Properties. The action maps appear to be like keybinding sets, so you can save entire different sets of actions with their own keybindings to each map you create. Then the actions are the core focus, where actions can be named and keybindings can be set, as well as which types of controllers are used. Finally the properties section allows for more detailed additions to each action such as other modifiers to apply to the input when used as well as the type of action.

After filling this out to the desired result, there is an option to “Generate a C# Class” from this new input system you have created. This provides you with the proper tools to utilize the asset you created within your programming system yourself. The context is a bit more awkward as it uses events, so you have to assign methods to them when using them in your own programming. They set this up in the Awake method for example:

controls.Player.Shoot.performed += _ => Shoot()

controls is the name of the InputMaster object (which is what they named the generated C# file from the input system), Player is the name of the action map, shoot is the name of the action from the input system, performed is a subset of that action, and finally Shoot is the method being subscribed to that event. The underscore is simply a place holder used for this programming syntax so it is necessary but I am unsure exactly why the syntax is like that.

I was then having an issue following the tutorial because they simply made controls (their InputMaster object) public so they could drag/drop the input system asset itself directly into the component so they were connected and running. When I did this the InputMaster object did not show up in my Inspector, even when made public. To get it to work at all, I found that I just needed to assign a new InputMaster to controls in the Awake method. I found that in the documentation provided here: Unity New Input System Manual

I then found that natively you could not use both the old input system and the new input system at the same time. So while this did get the new input system working and I could jump (which was the only action I assigned for testing), I could not move horizontally at all as the inputs for that just did not work anymore. Exploring the documentation further, I did find that you can switch back and forth between the old and new input system, as well as activate both at the same time, in the: Project Settings > Player, under: Active Input Handling. Upon setting that to both, I could move horizontally (with the old inputs) and jump (with the new inputs).

Installation Guide here: Unity New Input System Installation and Setup Documentation

Summary

This approach seems promising for setting up complex keybinding setups where you also want multiple devices. It does provide the base benefit of not needing to use strings with the input system anymore when doing the programming so that is a large benefit already. I would have to explore how to edit keybindings at runtime with this setup to see if it is a good final approach for this system that would also support letting the player set their own keybindings.