You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An "action asset" is an asset containing [input actions](Actions.md) as well as their associated [bindings](ActionBindings.md) and [control schemes](ActionBindings.md#control-schemes). These assets are distinguished by the `.inputactions` file extension and are stored in a plain JSON format.
7
+
An "input action asset" is an asset containing [input actions](Actions.md) as well as their associated [bindings](ActionBindings.md) and [control schemes](ActionBindings.md#control-schemes). These assets are distinguished by the `.inputactions` file extension and are stored in a plain JSON format.
10
8
11
-
## Creating Action Assets
9
+
## Creating Input Action Assets
12
10
13
11
To create an asset containing [input actions](Actions.md) in Unity, right-click in the Project window or open the `Assets` entry in Unity's main menu. From there, select `Create >> Input Actions`.
To bring up the action editor, double-click an `.inputactions` asset in the Project Browser click the "Edit asset" button in the inspector for the asset. Multiple action editor windows can be open concurrently (not on the same asset, though).
17
+
To bring up the action editor, double-click an `.inputactions` asset in the Project Browser or click the "Edit asset" button in the inspector for the asset. Multiple action editor windows can be open concurrently (not on the same asset, though).
20
18
21
19

22
20
23
21
The action editor comes up as a separate window which can optionally be docked into Unity's main UI.
24
22
25
23
>NOTE: For details about how action maps, actions, and bindings work, see the documentation on [actions](Actions.md).
26
24
27
-
Edits made in the action asset window are not saved automatically with the project by default. To save your changes, click `Save Asset` in the window's toolbar. To discard your changes, close the window and choose "Don't Save". Alternatively, auto-saving can be toggled on by ticking the "Auto-Save" checkbox in the toolbar. This will cause any change to the asset to automatically be persisted back to disk. This setting will take effect for all `.inputactions` assets and will persist across editor sessions.
25
+
Edits made in the action asset window are not saved automatically with the project by default. To save your changes, click `Save Asset` in the window's toolbar. To discard your changes, close the window and choose `Don't Save`. Alternatively, auto-saving can be toggled on by ticking the `Auto-Save` checkbox in the toolbar. This will cause any change to the asset to automatically be persisted back to disk. This setting will take effect for all `.inputactions` assets and will persist across editor sessions.
28
26
29
27
The editor window is divided into three panes.
30
28
@@ -34,10 +32,15 @@ The editor window is divided into three panes.
34
32
35
33
Multiple shorts are available to provide quick access to certain common operations.
36
34
37
-
|Shortcut|Description|
38
-
|--------|-----------|
39
-
40
-
35
+
|Shortcut (Mac)|Shortcut (Windows)|Description|
36
+
|--------------|------------------|-----------|
37
+
|⌘X, ⌘C, ⌘V|Ctrl-X, Ctrl-C, Ctrl-V|Cut, Copy and Paste. Can be used on actions, action maps and binding.|
38
+
|⌘D|Ctrl-D|Duplicate. Can be used on actions, action maps and bindings.|
39
+
|⌘⌫|Del|Delete. Can be used on actions, action maps and bindings.|
40
+
|⌥S|Alt-S|Save.|
41
+
|⌥M|Alt-M|Add Action Map.|
42
+
|⌥A|Alt-A|Add Action.|
43
+
|⌥B|Alt-B|Add Binding.|
41
44
42
45
43
46
>Pro Tip: You can search quickly by devices and/or control schemes directly from the search box. "d:gamepad" filters for bindings to gamepad devices whereas "g:gamepad" filters for bindings in the gamepad control scheme. Matching is case-insensitive and will match any partial name.
@@ -50,42 +53,71 @@ Multiple shorts are available to provide quick access to certain common operatio
50
53
51
54
* To add a new action map, click the plus icon in the header of the action map column.
52
55
* To rename an existing map, either long-click the name or right-click the action map and select "Rename" from the context menu.
53
-
* To delete an existing map, either right-click it and select "Delete" from the context menu or use the `Delete` key (Windows) / `Cmd-Backspace` (Mac).
54
-
* To duplicate an existing map, either right-click it and select "Duplicate" or use `Ctrl-D` (Windows) / `Cmd-D` (Mac).
56
+
* To delete an existing map, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
57
+
* To duplicate an existing map, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
55
58
56
59
### Editing Actions
57
60
58
61

59
62
63
+
* To add a new action, click the plus icon in the header of the action column.
64
+
* To rename an existing action, either long-click the name or right-click the action map and select "Rename" from the context menu.
65
+
* To delete an existing action, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
66
+
* To duplicate an existing action, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
67
+
68
+
If you select an action you can edit it's properties in the right hand pane of the window:
60
69
61
70

62
71
63
72
### Editing Bindings
64
73
74
+
* To add a new binding, click the plus icon on the action you want to add it to, and select the binding type fron the popup menu.
75
+
* To delete an existing binding, either right-click it and select "Delete" from the context menu or use the Delete key (Windows) / ⌘⌫ (Mac).
76
+
* To duplicate an existing binding, either right-click it and select "Duplicate" or use Ctrl-D (Windows) / ⌘D (Mac).
77
+
78
+
If you select an action you can edit it's properties in the right hand pane of the window:
The most important property of any binding is the [control path](Controls.md#control-paths) it is bound to. To edit it, click on the popup button for the `Path` property. This will pop up a Control Picker window.
85
+
69
86

70
87
88
+
In the control picker window, you can explore a tree of input devices and controls known to the input system to bind to. This list will be filtered by the action's [`Control Type`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_expectedControlType) property, so if the control type is `Vector2`, you will only be able to select any control which generates two-dimensional values (like a stick). The device and control tree is organized hierarchically from generic to specific. So, you can for instance navigate to "Gamepad", and choose the control path `<Gamepad>/buttonSouth`. This will then match the lower action button on any gamepad. But you can also navigate to "Gamepad", and from there scroll down to "More specific Gamepads" and select "PS4 Controller", and then choose the control path `<DualShockGamepad>/buttonSouth`. This will then only match the "cross" button on PlayStation gamepads, and not match any other gamepads.
89
+
90
+
Instead of browsing the tree to find the control you want, it is often easier to simply let the input system listen for input. To do that, click the "Listen" button. The list of controls will first be empty. Now you can start clicking buttons or actuating controls on the devices you want to bind to. The control picker window will list any bindings which would match the controls you pressed, and you can click on one to choose it.
91
+
92
+
Finally, you can choose to manually edit the binding path, instead of using the control picker. To do that, you can click the "T" button next to the control path popup. This will switch the popup to a text field, where you can enter any binding string. The advantage of doing this is that you are allowed to use wildcard (`*`) characters in your bindings. So you can for instance use a binding path such as `<Touchscreen>/touch*/press` to bind to any finger being pressed on the touchscreen (instead of manually binding to `<Touchscreen>/touch0/press`, `<Touchscreen>/touch1/press`, etc..).
93
+
71
94
#### Editing Composite Bindings
72
95
96
+
Composite bindings are bindings consisting of multiple parts, which form a control together. For instance a [2D Vector composite](ActionBindings.md#2d-vector) uses four buttons (left, right, up, down) to simulate a 2D stick input. You can learn more about how composites works and which types of composites there are [here](ActionBindings.md#composite-bindings).
97
+
98
+
To create a composite binding in the input action asset editor window, click the plus icon on the action you want to add it to, and select the composite binding type fron the popup menu. This will create multiple bindings entries for the action - one for the composite as a whole, and then, one level below that, one for each composite part. The composite itself does not have a binding path property, but it's individual parts do - and those can be edited like any other binding. Once you have bound all the composite's parts, the composite can work together as if you bound a single control to the action.
99
+
73
100
### Editing Control Schemes
74
101
102
+
Input Action Assets can have multiple [control schemes](ActionBindings.md#control-schemes) which let you enable or disable different sets of bindings for your actions for different types of devices.
To see the control schemes in the input action asset editor window, click the control scheme popup button in the top left of the window. This popup menu lets you add or remove control schemes to your asset. If your asset contains any control schemes, you can select a control scheme, and then the window will only show bindings belong to that scheme. If you select a binding, you will now be able to pick the control schemes for which this binding should be active in the properties view to the left of the window. When you add a new control scheme (or select an existing control scheme, and then select "Edit Control Scheme…" from the popup), a little window will open which lets you edit the name of the control scheme and which devices the scheme should be active for.
107
+
108
+
## Using Input Action Assets
78
109
79
110
### Auto-Generating Script Code for Actions
80
111
81
112
One of the most convenient ways to work with `.inputactions` assets in script is to generate a C# wrapper class for them automatically. This obviates the need for manually looking up actions and maps using their names and also provides easier ways for setting up callbacks.
82
113
83
114
To enable this, tick the `Generate C# Class` in the importer properties in the inspector of the `.inputactions` asset when selected in Unity and hit "Apply".
// MyPlayerControls is the C# class that has been generated for us.
101
-
// It wraps around a reference to the .inputactions asset we created
133
+
// It encapsulates the data from the .inputactions asset we created
102
134
// and automatically looks up all the maps and actions for us.
103
-
publicMyPlayerControlscontrols;
104
-
105
-
publicvoidAwake()
106
-
{
107
-
// Tell the "gameplay" action map that we want to get told about
108
-
// when actions get triggered.
109
-
controls.gameplay.SetCallbacks(this);
110
-
}
135
+
MyPlayerControlscontrols;
111
136
112
137
publicvoidOnEnable()
113
138
{
139
+
if (controls==null)
140
+
{
141
+
controls=newMyPlayerControls();
142
+
// Tell the "gameplay" action map that we want to get told about
143
+
// when actions get triggered.
144
+
controls.gameplay.SetCallbacks(this);
145
+
}
114
146
controls.gameplay.Enable();
115
147
}
116
148
@@ -134,4 +166,6 @@ public class MyPlayerScript : MonoBehaviour, IGameplayActions
134
166
135
167
### Using Action Assets with `PlayerInput`
136
168
137
-
### Loading Action Assets
169
+
The [`PlayerInput` component](Components.md#playerinput-component) provides a convenient way to handle input for one or multiple players. It requires you to set up all your actions in an Input Action Asset, which you can then assign to the [`PlayerInput`](Components.md#playerinput-component) component. [`PlayerInput`](Components.md#playerinput-component) can then automatically handle activating action maps and selecting control schemes for you. Check the docs on [GameObject Components for Input](Components.md) to learn mode.
0 commit comments