How to Swap Action Maps in Unity’s New Input System

Chris Hilton
3 min readNov 3, 2022

--

Objective: To learn how to swap Action Maps with Unity’s New Input System.

So far we have only looked at using one Action Map, but what happens if we have multiple Action Maps and we want to be able to switch through them at runtime? Only one can ever be active, so what is the simplest process to make this happen? Let’s take a look…

Setup a Second Action Map

Let’s create a second Action Map called Driving’. To show the difference between the current active Action Maps, I am going to change the movement of the ‘DrivingActions to be on the X and Z axis instead of X and Y for our ‘PlayerAction movements (we will see this at the end of the article).

Action setup and properties
Binding setup and properties

I have set this up exactly the same as the ‘PlayerAction Map (article here if you are unsure how to setup an Action Map).

Creating a Button to Switch Action Maps

We are also going to need a button that is going to switch the Action Maps from Player’ to ‘Driving’:

Let’s Build the Logic Through Code and Test the Results

Now, we need to build the logic in our script so that we can test the Action Map switch at runtime:

First we need to register to the performed event and the newly created method will simply Disable() the ‘PlayerAction Map and Enable() the ‘DrivingAction Map.

How simple!

Simple Movement Code to Test

Let’s take a quick look at the simple movement code I have setup to show the difference between the ‘Playermovement and the ‘Drivingmovement:

As their can only be one Action Map active at a time, we don’t need to add additional logic to check the current active Action Map, it will automatically work out which method is attached to which Action Map.

Testing the Results

As mentioned above, if the ‘PlayerAction Map is enabled, we will have movement on the X and Y axis, but if ‘Driving’ is enabled, we will have movement on the X and Z axis:

Success!! The movement changed.

Next Article

“Tap & Hold With Unity’s New Input System”

--

--