Unity New Input System
Understanding what Input Actions are:
Unity has finally reworked the Input system which allows for more diverse interactions for your games and or applications. The new input system basically has something called an “Input Action” which is an consolidated component that houses all input interactions together. It is much more organized than before and users will be able to see all the different input actions within a glance.
Using the New Input System:
To get started with the new Input system we first need to install the asset via the package manager in the Unity Registry. By default the New Input System isn’t part of the basic core of Unity.
Once the Input System as been installed into your Unity, we can start by creating an new Input Actions component. In the projects window we can click the + icon or right click from the mouse to create an new Input System. You might have to scroll all the way down to the bottom of the drop down menu to see the Input Action selection.
Once that is completed you will see an new component which you can rename.
To open the New Input Actions, simply double click on the newly created component to bring out an new window. This window is the new Input Actions that houses all the controls within the game/application. In the example below I have already created something called “Dog Controls” under the “Action Maps”.
Action Maps: are the general settings for that individual setup. For example I can have an Action Map dedicated to my Player, another action map for Driving and finally another Action Map for my Main Menu. Each Action Map has their own purpose and own Actions, and Unity is able to switch between these Action Maps on runtime. (aka. I can have the player controls swap to the Driving controls once my player has entered an vehicle and vice versa.)
Actions: are the actual Input properties that belong to the Action Map. For example, I have “Movement” within the Dog Controls action map. Within the Movement Actions, are the input controls for the keyboard “WASD”.
As you can see, the format for these Input Actions are in a much organized manner. Actions Inputs are not just limited to Movement, I also have other inputs for “Bark”, “Run” and also “Die” as an example and these Actions all have different properties attach to them.
If if you noticed, there are several actions that involve 1 or 2 buttons combined together, this is the beauty of using the new Input Action is that you are able to easily chain up different inputs together to create one overall Input sequence.
Take “Die” for example, I have the setup to have two buttons to trigger the Die function which is when the Player presses “D + F” key together. This function uses the One Modifier binding.
And this is how the setup looks like with the Key Bindings. How the modifier function works basically means that if the player presses the D key, nothing happens. But once the player presses the D + F key then it should trigger the “Die” Action.
Unity also has the ability to add in “Interactions within the Key Bindings. For example if you want to hold a button for a certain duration before being able to toggle an function, you can with Action Map Interactions.
In this example we see for the Run function we have an regular key binding with the Left shift Button. I added an Interaction of “Hold” since I want the player to hold down the left shift key to preform the run function.
Once you added that interaction in, you will be greeted with the Press Point (which I left set to Default) and the Hold Time which is the duration the player requires to hold the Left Shift button for. By default it is set to 0.4 seconds, but you can uncheck the box and add in your own duration amount.