Working with Unity New Input System
Learning how to swap between two or more Action Maps:
Now that we have a proper understanding of how Action Maps work and how you can apply them into our script, it is time to learn how to swap between multiple Action Maps. For example if you want to swap between Player Input and vehicle Input.
Learning how to Swap Action Maps:
To start we first need to create two Action Map Inputs, so far we should only have 1 Input Actions which is Player Input. We can create another new input map by simply clicking on the “+” icon or right clicking and creating new Input Actions. We can name these to whatever we desire, for my example I am going to name it Vehicle Input.
In this Vehicle input I am basically going to have some basic Actions just for demonstration. The important factor is that within the Actions for the Player Action Maps I would need a toggle to allow the swapping of Inputs from Player > Vehicle. In this example I will use the “T” in the Players Input to transfer input controls into the Vehicle state. This Action is going to be a Key binding.
The logic behind how the the swapping mechanism works is basically enabling and disabling the Action Input when we press the “T” key. Therefore within the main Player script, we are going to create a new “performed” function for the “T” binding.
Inside this new method is where we are going to enable and disable the two Action Maps. First we are going to “disable” the regular Player Controls.
Then we are going to enable the Vehicle Input system.
As a testing purposes we are just going to swap to the Vehicle Mode once, but for real practical purposes you might want to input an proper method to toggle between Vehicle and Player movements.
Save the script and turn your attention back into Unity, now when you test out the script and watch the Action Map swap when you press the “T” binding.