How to Swap Action Maps: Unity Input System

Thomas Mauro
3 min readNov 2, 2022

--

Challenge:

  • Create an Action Map for Driving and switch to it via the ‘T’ key.
  • Should be able to move in 3D space with WSAD (Left/Right/Forward/Backward)

By now you know how to get things set up. I am using the same project with the Player Action Map and the Change Color and Rotate Actions.

  • Make a new Action Map and call it Driving
  • Make an Action on the Player and call it Driving State
  • Make a Binding Button with Path set as the ‘T’ key
  • Save the Asset

Now let's get the performed actions via code on the Player.cs. This enables these inputs to register as you may understand by now. You should know how to get the method started by now.

Don’t forget to save. The next step is to set up our Driving Asset.

  • With the Driving Action Map selected create a new Action and name it Movement. And SAVE ASSET
  • Delete the current Binding
  • Select the Movement Action and make the Properties Value/Vector2
  • Create a Binding on the Movement of Up/Down/Left/Right Composite (2D Vector)
  • Set the correct key bindings and SAVE ASSET

I named that 2DVector Binding WSAD because I will now make another set of bindings for the arrow keys.

  • With Movement selected click the + and select Up/Down/Left/Right Composite (2D Vector) rename it Arrows
  • Set up the Bindings and save your asset

Now for the rest of the code required to make it work. I will use something that was used in a previous article. A var = move then the transform.Translate.

The only thing left is to test this out and see if it works. At first, it will be on the Player map where I can rotate and change to a random color. After I press ‘T’ then I will have the WSAD movement and be in the Driving State. I found with this current set up whatever color it is when you go to the driving state the color it will stay and also rotate is no longer available. This concludes a successful test.

--

--