Using the new Unity input system
Handling user inputs is paramount for efficient game development. Unity provides two built-in systems for handling inputs. These two systems are referred to as the old Input Manager and the new Input System.
Unity’s new Input System is an upgrade to the old Input Manager. It was officially released recently addressing the limitations of the input manager. It may appear difficult to use. However, it offers more flexibility and is safer to use once you get the hang of it.
In particular, the new Input System works seamlessly across various platforms. As a result, you can save time working on your project and focus on developing a great game instead of wrangling the input manager.
In this article, you will learn how to set up and use Unity’s new Input System for input controls in your game projects.
How to install the new input system
Let’s start by installing the new Input System in your project.
New Input System Requirements
Note that the new Input System has some requirements that your project must meet in order for it to function. You probably meet these requirements, but I’ll list them here for you.
- Unity 2019.1 or newer
- .NET 4 runtime
If you have met these requirements, you can install the new Input System with this step-by-step guide.
Install the new Input System in Unity
- In the menu bar, click Window > Package Manager.
- In the Package Manager, click Input System from the list.
- Click Install.
📄 Resources:
After installing the package, you will be asked whether you want to enable the new input backends. Click Yes to enable the new input backends and disable the old ones.
Now that you have successfully installed and activated the new Input System, we will explore how you can use it for input controls.
How to use the new Input System to get input from a device
You have two options when using the Input System to gather input. You can either read the current state of the input, or you can use the Input Actions system to hook into any updates.
Read the current Input System state
The quick and dirty way to gather input is to read the current state of the input device directly with a script. In this example, we bind the space input from the keyboard to a jump action. This is an implicit binding. Your Update method continuously polls the Input System and checks if the space input was pressed in the frame. If it was, then the action is performed.
using UnityEngine;
using UnityEngine.InputSystem;
public class GetInput: MonoBehaviour
{
void Update()
{
if (Keyboard.current.space.wasPressedThisFrame)
{
// Make the player jump
}
}
}
In the example script above, the new input system was used to retrieve input from the keyboard to trigger an action.
Create a free account, or log in.
Gain access to free articles, game development tools, and game assets.