New Unity Input System: Getting Started

In this Unity Input System tutorial, you’ll learn how to convert player input in your existing projects from the old Input Manager to the new Input System. By Ken Lee.

4.1 (18) · 1 Review

Download materials
Save for later
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Handling Actions

The new Input System provides four ways to handle action events.

In this tutorial, you used the SendMessages approach. You can change this option in the Behavior field in the PlayerInput component.

Input Behavior

SendMessage and BroadcastMessage are the simplest ways to handle actions. When you use these two options, the system invokes the method with a name matching the name of the action.

For example, in this tutorial, the Jump action invokes OnJump() and the Move action invokes OnMove().

BroadcastMessage is similar to SendMessage, except it can invoke the methods on any child GameObject. These two options are easy to use because you don’t need to configure anything to use them.

Using Invoke Unity Events

When using Invoke Unity Events, you configure the action much as you’d configure a button click in Unity UI.

This approach is more flexible, letting you use different methods in different objects. Those GameObjects don’t even need to have the PlayerInput component.

Using Invoke C# Events

This approach is as flexible as Invoke Unity Events. You can define the methods you want to use instead of using methods with a specific name. However, if you use this approach, you need to write code to control which methods to invoke.

Here is a sample of how this looks:

private void Awake()
{
    animator = GetComponentInChildren<Animator>();
    rigidbody = GetComponent<Rigidbody>();

    // 1
    GetComponent<PlayerInput>().onActionTriggered += HandleAction;
}

private void HandleAction(InputAction.CallbackContext context)
{
    // 2
    if(context.action.name == "Jump")
    {
        HandleJump();
    }
}

Here’s what this code does:

  1. Gets the PlayerInput component and registers the method to onActionTriggered.
  2. Controls which method to call for different actions.

Using the Update Cycle of the New Input System

In the old Unity Input Manager, you checked the input in every frame using Update(). In the new Input System, you may wonder when actions are being sent, and if they’re sent before every Update().

The new Input System uses a different update cycle that’s independent of MonoBehaviour‘s lifecycle. You can read more about it in Unity’s Execution Order documentation.

The system offers three Update Modes to control the update cycle. You can configure them in Project Settings ▸ Input System Package ▸ Update Mode.

Different update methods

Take a look at each of these nodes:

  • Dynamic Update: Processes events at irregular intervals determined by the current frame rate. This is the default setting.
  • Fixed Update: Processes events at fixed-length intervals. Time.fixedDeltaTime determines the length of the interval.
  • Manually: Events aren’t processed automatically; you process them when you call InputSystem.Update(). If you want a check similar to the old system, you can call InputSystem.Update() in Update().

These new options, as part of the new Input System, give you a lot more control over input, whilst also making it easier to support multiple input devices :]

Where to Go from Here?

Download the completed project using the Download Materials button at the top or bottom of this tutorial.

In this Unity Input tutorial, you’ve learned:

  • The basic layout of the new Input System.
  • How to use actions and bindings.
  • How to handle different kinds of player input efficiently.

To test your skill, try to add a Pause action to the game!

To learn more about the new Input System, you can read the Unity Input System manual.

I hope you have enjoyed this tutorial! If you have any questions or comments, please join the forum discussion below.