Creating Your First Action Using Unity’s New Input System
Objective: To learn how to create your first Action using Unity’s New Input System.
What is an Action
An Action is something that triggers a callback in response to player input.
E.g. If we were in a UI menu of a game, usually the A and B buttons on an Xbox controller allow you to proceed forward or backwards in the menu.
Alternatively if we were in game, A might jump and B would crouch.
Pressing any keys/buttons that have been mapped for player input, would trigger a callback response to perform an Action.
How to Add an Action to an Action Map
There are 4 different ways you can create an Action including:
- Using the Action Editor
- Embedding them in MonoBehaviour Components
- Manually loading them from JSON, or
- Creating them directly in code.
This article is going to look at creating Actions through the Action Editor.
With the Input Action Window open, simply press the ‘+’ button in the Actions section:
This will automatically add a new Action for us to rename, along with a key binding for us to choose:
For this example I am going to create a ‘Jump’ Action and map this to the ‘Space’ key by first renaming the Action.
When you added the Action you will also now see a third section called ‘Action Properties’. Let’s leave the ‘Action Type’ as ‘Button’ for now, but there are a few other options to choose from.
Now click in the ‘No-Binding’ field. This will bring up a new section called ‘Binding Properties’, which will allow us to map our key:
When we click in the ‘Path’ drop down field, a new pop up window appears giving us a few different options as to how we want to locate the ‘Space’ key:
Search Box - Typing ‘Space’ will show the key to map.
By Location of Key - This will bring up a drop down box which we can cycle through to find the key.
By Character Mapped to Key - Shortened list compared to above.
Listen Button - The easiest option here to use, which when clicked will wait for your input and map it to the key pressed:
You can also have many different bindings all pointing to the same Action.
Lastly, you always want to make sure you are saving your asset before closing out of the window:
You have now created your Action Maps first Action with it’s associated binding!
Article Links
Next Article
“Scripting Actions in Unity’s New Input System”