Search Unity

Learn the Input System with updated tutorials and our sample project, Warriors

, novembro 26, 2020

With the Input System, you can quickly set up controls for multiple platforms, from mobile to VR. Get started with our example projects and new video tutorials for beginners and intermediate users.

Input is at the heart of what makes your real-time projects interactive. Unity’s system for input standardizes the way you implement controls and provides new advanced functionality. It’s verified for Unity 2019 LTS and newer versions (see the documentation for a full list of supported input devices). 

Our new tutorial content can help you to get started quickly, even if you’re completely new to developing for multiple platforms. If you’re already familiar with the workflows, learn more about how to use the Input System to drive (other) Unity tools like Cinemachine or Unity UI with Warriors, our main example project.

This Meet the Devs session from March explains why we created this new system and includes  a demo that outlines workflows for setting up local multiplayer, quickly adding gamepad controls, spawning new players, and implementing mobile controls. Rene Damm, the lead developer of the Input System, also answers questions from the audience about tooling and the team’s roadmap. 

Roll-a-Ball: Input System for beginners

If you’re a beginner who just wants to get to know the basic input workflows for Unity, check the updated Roll-a-Ball project on Unity Learn. It walks you through first steps like installing the Input System package, adding a Player Input component, and applying input data to the Player.

The Roll-a-Ball project helps beginners get acquainted with Input System basics.

The Prototype Series: Controlling a spaceship

The Procedural Boss tutorial from the Prototype Series uses our new Supernova art pack.

Our Prototype Series also uses the Input System, as you can see in this video and example project on creating a boss with procedural animation. The spaceship’s input action asset uses input for movement controls, shooting laser projectiles, and boosting.

Warriors: Intermediate integrations and gameplay scenarios

Warriors is a project that demonstrates more intermediate tooling and APIs with the Input System in a typical third-person local-multiplayer cross-platform game setup. It’s available for Unity 2019 LTS and will be updated for the 2020 LTS version when it’s released next year. You can download the project from GitHub, where we have three branches available:

  •  V1 captures the state of the project at the time of the Meet the Devs session mentioned above;
  •  V2 is what we’ve used for the most recent Input System Unite Now session (see below);
  •  We’re continuing our work in the Master branch.

The project is built around characters that can be controlled in both Single Player and Local Multiplayer modes. When the Game Manager is set to Local Multiplayer, it will instantiate several instances of the Warrior prefab. As the Warrior prefab is set up to use the Input System’s Player Input component, each instance of the Warrior will automatically have a connected input device paired to it.

Control schemes

The control scheme for this Warrior is set up for cross-platform play and auto-switches between the keyboard and different gamepads. This setup provides an example of applying smoothing to the raw runtime input data so that the character’s directional movement is even no matter which axes input (keyboard keys or gamepad joystick) the player uses. The following control scheme also uses a button press for a basic attack animation.

The Warrior’s Input Action asset is also set up for two different Action Maps: one for controlling the character (Running and Attacking), and the other for controlling input for the menu. A game or any other interactive project usually has different states with different control requirements that share the same input bindings.

For example, pushing a joystick in one direction will cause the Warrior to run toward that axis. However, when the game is paused, the player can use the joystick to navigate between different selectable buttons and options in the pause menu.

Using the Input System, you can easily set up different Action Maps for various control scheme scenarios and switch them, per PlayerInput component, at runtime with a simple API:

Interacting with the UI

Once you have set up an Action Map for interacting with the UI, actions can then be assigned to the Event System’s UI Input Module:

In the Warriors project, each player can pause the game and interact with the pause menu. The overlay UI consists of a few option buttons and a context-changing panel on the right. The Input System UI Input Module applies actions assigned to interacting with any Unity UI component with Interactable enabled (such as Buttons and Sliders).

This UI interaction will be isolated for the specific player that pressed pause. For example, if Player 3 pauses the game, then Player 1 and 2 will not be able to interact with it, and only Player 3 will be in control. When Player 3 unpauses the game, all Player controls are resumed. We do this by calling the following methods on a PlayerInput component:

Runtime rebinding 

In the UI Menu, there is a context panel for runtime rebinding controls. This allows you to perform an Interactive Rebind for a specific Input Action and set a new input binding to it. For example, when using a PlayStation controller you could rebind the Attack action from the Cross button to another input button such as Triangle or R2.

This rebind applies as an override to a specific PlayerInput component. For example, Player 2 will be able to rebind their Attack button to a different button, but this will not affect Player 3’s use of their Attack Input Action.

The API for setting up an interactive rebind also contains an operation for when the rebind has completed. This allows you to set up your own control when updating the UI, saving the game state or changing any other gameplay element based on this event.

Input System and Cinemachine 

Besides the Input System’s integration with the Event System and Unity UI, the Warriors project also demonstrates how it can be set up to work in concert with Cinemachine. A typical camera setup for a third-person game would feature an orbiting follow camera where the view direction is set by a mouse position or joystick push direction. The Cinemachine Input Provider component can be added to a Cinemachine Free Look camera rig, which allows an Input action to send Vector 2 axis data directly into Cinemachine’s axis control values. In the image below, you can see that the CinemachineInputProvider is using the input data from the Look Input Action.

The Input System APIs: Display data through UI example

The Input System also contains a variety of APIs so that other systems can access data at runtime that can be displayed in the UI or other visuals. The Warriors example project uses data from Player Input to display information such as the current player device, player input ID, or even to update the UI-based rebind controls on the current binding. We created a custom system that takes the device and binding strings and returns a specific icon.

For example, if the player is using an Xbox controller and the Attack action is bound to the northern context button, this will display a Y button icon. However, if the player is using a keyboard, then it will display a string for the currently bound keyboard key. You are welcome to extract and use this Device Display Configurator tool in your own projects.

Input System package samples and documentation

The Input System package also contains several extra samples that you can explore in the Package Manager. You can use these as a reference and extend or adapt them for your own projects. You can also find the official documentation there, including this Quick start guide

Coming up: Input System 1.1

Input System 1.1 is currently in preview, and it brings lots of fixes and some improvements. You can now save and load rebinds as JSON (see the RebindSaveLoad.cs sample script) and Device layouts can now be precompiled, greatly reducing instantiation time and garbage collection (GC) heap cost for these devices.

Looking for more content? Let us know!

We hope that the sample project and the other learning materials will help you get started with using the Input System to bring your ideas to life. Please share what you want to learn next in the comment section below. Also, keep an eye on the Input System page for more tutorials and other resources.


19 replies on “Learn the Input System with updated tutorials and our sample project, Warriors”

Why this is not part of the core yet? It doesn’t make sense to have it as an asset external to Unity (aka package, repo, you name it).

sadly as nice as this demo is, it doesn’t offer me any more clarity on how to achieve what i want, instead it pretty much establishes what’s already been said, just with an example. i remain confused in the same ways as before. assumptions seem to be made on how many players there are, if not enough controllers are there then multiple players are moved form one controller even after another is added.

Hi RR7!

Im sorry you didn’t find that it helped you in what you want to achieve; im curious what your desired goal and setup is? What particular areas are you confused about?

In terms of spawning number of players; for the next release im going to work on updating the project so that you can either manually set number of players (As it currently is) or switch to automatic setup (Detect 4 possible input devices are plugged in and spawn up to that many). Unfortunately, I was not able to get this added in-time for this release but will add it to the next one. :)

Great post and overview. This system will be gold when remaining bugs and performance issues are addressed. I hope bugs take priority over new features since after 1.0, many of us are already using the new InputSystem in production. It is a leap forward over the old-gen system so I’m looking forward to future releases.

Hey NongBenz!

Which remaining bugs and performances issues are you running into? have you reported them through the Bug Reporter?

I’m going to try it now. These posts in unity blogs are pure Gold. They help a lot to developers get their hands into these new systems easily and try them. Thanks Kristyna & Andy!

I think integrating with VR controllers is a good idea for a future blog as well. There’s a large amount of VR games which are diorama style, or you have games like star wars squadrons. There’s a lot more games now where the VR side is optional so it would be nice to see an example which could work.

Good point! Admittedly, I am not savvy with XR platforms, features and tools so did not write about them or implement them into this blogpost. And as you have pointed out; it would be probably be ideal to have a more XR Input focused blog/video that covers the typical setups, most-used hardware and edge-cases. Ill talk to more knowledgable folks internally about this. :)

I’d love to see an XR focused Input System review also Andy.. This blog post and content was really good and I do feel like I’ve come up to speed a bit. I notice in the XRIntegrations examples on Github, that project is making heavy use of Input Action References, and employs some kind of Action Manager on each XR controller for switching contexts, ultimately a bit confusing how this is working, but it does..a vid would be great though to better understand that more complex example.

Very interesting stuff, however in the title you mention VR, but impossible to find anything on it in the article nor in the documentation. Is there info about it somewhere else?

Hey Thibault!
Im not savvy with VR tools and platforms; but there are VR controller inputs in the Input Bindings menu when setting up Input Actions. I will look into more VR focused content in the future. :)

Comments are closed.