Using Action Maps

This doc will go over how to use Action Maps in script for the New Input System in Unity 6.3 ...

Now that you have an example of an Action Input, we can use this within code. That said, there are two main ways to apply this information with the use of a generated C# Class, or without.

The C# Class component offers a tool to get to the Actions you've mapped faster, whereas not using it allows you to use the code within your own scripts as needed. It's completely up to you which approach you prefer.

First thing we need to do is link to the Input Actions data.

  • Either click the parameter at the top of the 'Input Actions' tab, or usually found within your default Assets folder.

Location of Input Actions file...
  • Open a script, and add the 'InputSystem' namespace at the top.

  • Create a variable for the Input Actions.

circle-exclamation
  • Add variables for all the Actions we want to reference.

  • Add variables for all the Action variables we want to reference.

  • Enable and Disable the Action Map on load.

  • Define the Input Action variables in the 'Awake()' method.

  • Add the values of the Actions in the 'Update()' or 'FixedUpdate()' method, depending on if physics are involved for example.

With that you have your variables for use in script as you see fit. Some features such as buttons can be checked for a specific frame or in general, including :

Final result

The final script would look like the following :

With that we have access to our Input Action Maps and Actions. Now, all you have to do if you want to add a new controller is update the Actions directly and it will just work!

Last updated