Input System Example

Example on implementing input reading using Input System

1. Install Input System Package

Go to Window -> Package Manager

Search from the Unity Registry

Type "Input System" in the search bar and install

2. Create Input Actions Asset

Create input actions asset by doing right-click in the folder -> Create -> InputActions

3. Add Input Actions

Open the input actions asset and create new action map by clicking "+".

Create new action called "GasInput" and set it's action type to "Value" and Control Type to "Any".

Add bindings by clicking "+". As a path select the input button

Repeat the same steps for the Brake Input

Create new action map for the steering input. Add Positive/Negative binding for the WASD controls

Add binding for the left stick horizontal input

Create Handbrake action of type "Button" and add input paths

Save the asset and close the window.

4. Create a Script

Click on the InputActions asset, check the "Generate C# Class" toggle and click "Apply"

Create new C# script

Open the script. Add the namespace by typing "using Assets.VehicleController". Inherit from the IVehicleControllerInputProvider

Create a new object of type PlayerInputActions (the generated class from the input actions) in Awake.

Implement the interface

In Visual Studio, click on the IVehicleControllerInput provider, which should have a red wavy underline, press Alt + Enter and select "Implement Interface"

GearUp/GearDown should be actions of type button. In code, you can read the value by calling inputActions.Vehicle.GearUp.WasPerformedThisFrame().

NitroBoost should be implemented like Handbrake.

Pitch/Yaw/Roll should be implemented like HorizontalInput.

Last updated