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 ‘Driving’ Actions to be on the X and Z axis instead of X and Y for our ‘Player’ Action movements (we will see this at the end of the article).
I have set this up exactly the same as the ‘Player’ Action 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 ‘Player’ Action Map and Enable() the ‘Driving’ Action Map.
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 ‘Player’ movement and the ‘Driving’ movement:
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 ‘Player’ Action 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.
“Tap & Hold With Unity’s New Input System”