Unity’s New Input System: Switching Action Maps

Hello all!

Today, I will be going over how to switch between action maps using C#!

I press T to enter and exit the driving action map

Setting Up the Action Maps

Action maps are used when you want to change the inputs for different tasks. My case is switching from Player to Driving modes.

Player Action Map

I only set one action for the player to demonstrate the switch when I press T.

Driving Action Map

In the driving action map, I set the actions to follow Vector 2 and I added a way to switch back to the Player action map.

Don’t forget to generate a C# class of this InputAction asset in the Inspector.

Switching Action Maps in Script

Get a reference to the InputActions asset>Enable the Player action map>then setup what the EnterCar action does.

So, when you hit T in Player mode, I made a log saying that I entered the car>Disabled Player>Enabled Driving>Then set what happens when I press T again while in Driving mode.

Simple Driving Code

When in driving mode and press WASD, it gives a value. I just read the Vector2 values and set them to their corresponding axis.

To move forward in 3D space, you either use x or z. Using y would just raise the player.

Then to rotate the car, I set left and right to rotate on the y axis.

That was how to switch action maps using code!

Next up, setting up different taping and holding actions!

See you then!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Marcus Cohee

I am starting Unity and learning the ropes as I go! Let’s take this journey together!