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
DOCS: ISX-1883 Updated manual documentation to provide guidance for how to work with project-wide actions as an asset. (#1867)
* DOCS: Doc and UI updates reflecting change to storing project wide actions as asset.
* DOCS: Amendments to PlayerInput manual page.
* DOCS: ISX-1856 Improved documentation on PlayerInput component in workflows page.
* DOCS: Added documentation of the project settings action editor "more" menu and how to use it.
---------
Co-authored-by: Håkan Sidenvall <[email protected]>
Co-authored-by: Lyndon Homewood <[email protected]>
-[Type-safe C# API Generation](#type-safe-c-api-generation)
9
10
10
11
An Input Action Asset is an Asset which contains a set of [Input Actions](Actions.md) definitions and their associated [Bindings](ActionBindings.md) and [Control Schemes](ActionBindings.md#control-schemes). These Assets have the `.inputactions` file extension and are stored in a plain JSON format.
11
12
12
-
### Why use an Input Action Asset instead of configuring actionsin the Project Settings window?
13
+
The input system creates an Action Asset when you set up the [default project-wide actions](ProjectWideActions.md), but you can also create new Action Assets directly in the Project window.
13
14
14
-
Input Action Assets contain the same type of data that you see in the input settings in the Project Settings window, but instead of stored as part of your project settings, they are contained in an asset.
15
+
For most common scenarios, you do not need to use more than one Input Action Asset. It is usually simpler to configure your project-wide action definition in the Project Settings window.
15
16
16
-
For most common scenarios, you do not need to use an Input Action Asset. It is usually simpler to configure your project-wide action definition in the Project Settings window.
17
-
18
-
Input Action Assets exist because, in earlier versions of the Input System package, they were the _only_ way to configure actions. Now that you can configure actions in the Project Settings window, creating Action Assets is a largely redundant workflow, but it still exists for backwards-compatibility.
19
-
20
-
#### Type-safe C# API Generation
21
-
22
-
Input Action Assets have a feature that is not present for project-wide actions, which is that you can **generate a C# class** from your action definitions, which allow you to refer to your actions in a type-safe manner from code. This means you can avoid looking up your actions by string. This is one reason you might choose to use an Action Asset instead of the project-wide actions defined in the Project Settings window. See below for more information on this.
23
17
24
18
## Creating Input Action Assets
25
19
@@ -34,6 +28,11 @@ The Actions Editor which opens is identical to the [Actions Editor in the Projec
34
28
35
29
## Using Input Action Assets
36
30
31
+
32
+
## Type-safe C# API Generation
33
+
34
+
Input Action Assets allow you to **generate a C# class** from your action definitions, which allow you to refer to your actions in a type-safe manner from code. This means you can avoid looking up your actions by string.
35
+
37
36
### Auto-generating script code for Actions
38
37
39
38
One of the most convenient ways to work with `.inputactions` Assets in scripts is to automatically generate a C# wrapper class for them. This removes the need to manually look up Actions and Action Maps using their names, and also provides an easier way to set up callbacks.
@@ -118,4 +117,4 @@ void Start()
118
117
}
119
118
```
120
119
121
-
> __Note:__ This default actions asset is entirely separate from the default actions that appear in the project-wide actions in the Project Settings window, and should also be considered outdated and redundant.
120
+
> __Note:__ This default actions asset is older than, and entirely separate from the [default project-wide actions](ProjectWideActions.md). It is a legacy asset that remains included in the package for backward compatibility.
Copy file name to clipboardExpand all lines: Packages/com.unity.inputsystem/Documentation~/Actions.md
+15-51Lines changed: 15 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,11 @@ Actions also make it simpler to create a system that lets your players [customiz
29
29
30
30
## Overview
31
31
32
-
When scripting with Actions in the Input System, there are number of important classes you can use, which are described here:
32
+
When scripting with Actions in the Input System, there are number of important API you can use, which are described here:
33
33
34
-
|Class|Description|
34
+
|API name|Description|
35
35
|-----|-----------|
36
-
|`InputSystem.actions`|A reference to the set of actions configured in the [Input Actions editor](ActionsEditor.md).|
36
+
|[`InputSystem.actions`](../api/UnityEngine.InputSystem.InputSystem.html)|A reference to the set of actions assigned as the [project-wide Actions](./ProjectWideActions.md).|
37
37
|[`InputActionMap`](../api/UnityEngine.InputSystem.InputActionMap.html)|A named collection of Actions. The API equivalent to an entry in the "Action Maps" column of the [Input Actions editor](ActionsEditor.md).|
38
38
|[`InputAction`](../api/UnityEngine.InputSystem.InputAction.html)|A named Action that can return the current value of the controls that it is bound to, or can trigger callbacks in response to input. The API equivalent to an entry in the "Actions" column of the [Input Actions editor](ActionsEditor.md).|
39
39
|[`InputBinding`](../api/UnityEngine.InputSystem.InputBinding.html)|The relationship between an Action and the specific device controls for which it receives input. For more information about Bindings and how to use them, see [Action Bindings](ActionBindings.md).|
@@ -46,11 +46,7 @@ Each Action Map has a name ([`InputActionMap.name`](../api/UnityEngine.InputSyst
46
46
47
47
The simplest way to create actions is to use the [Input Actions editor](ActionsEditor.md) in the Project Settings window. This is the primary recommended workflow and suitable for most scenarios.
48
48
49
-
However, because the input system API is very open, there are many other ways to create actions which may suit less common scenarios. For example:
50
-
51
-
- You can create [Input Actions assets](ActionAssets.md) which define a set of action data similar to that defined in Project Settings, but is instead stored in a self-contained asset (this is an outdated workflow but is still supported).
52
-
- You can manually load Actions from JSON data.
53
-
- You can create Actions entirely in code, including setting up the bindings.
49
+
However, because the input system API is very open, there are many other ways to create actions which may suit less common scenarios. For example, by loading actions from JSON data, or creating actions entirely in code.
54
50
55
51
### Creating Actions using the Action editor
56
52
@@ -62,18 +58,11 @@ For information on how to create and edit Input Actions in the editor, see the [
62
58
63
59
# Other ways to create Actions
64
60
65
-
The simplest way to create actions is to use the [Input Actions editor](ActionsEditor.md) as described above. However, because the Input System package API is open and flexible, you can create actions using alternative techniques. These alternatives might be more suitable if you developing something unusual or want to customize your project beyond the standard workflow.
66
-
67
-
### Creating Actions in Input Action Assets
68
-
69
-
You can create actions that are stored in an Asset instead of in your Project Settings, by creating an [Action Asset](ActionAssets.md). This workflow used to be the main workflow in previous versions of the Input System package, but has been superseded by the [Input Actions editor](ActionsEditor.md) in the Project Settings window, which provides a simpler workflow.
70
-
71
-
However it is still possible to create [Action Assets](ActionAssets.md) which contain a complete set of Action Maps, Actions and Bindings, and use those instead of the project-wide Actions that are defined in the Project Settings window.
72
-
61
+
The simplest way to create actions is to use the [Input Actions editor](ActionsEditor.md) to configure a set of actions in an asset, as described above. However, because the Input System package API is open and flexible, you can create actions using alternative techniques. These alternatives might be more suitable if you want to customize your project beyond the standard workflow.
73
62
74
63
### Creating Actions by declaring them in MonoBehaviours
75
64
76
-
As an alternative workflow, you can declare individual [Input Action](../api/UnityEngine.InputSystem.InputAction.html) and [Input Action Maps](../api/UnityEngine.InputSystem.InputActionMap.html) as fields directly inside `MonoBehaviour` components, like this:
65
+
As an alternative workflow, you can declare individual [Input Action](../api/UnityEngine.InputSystem.InputAction.html) and [Input Action Maps](../api/UnityEngine.InputSystem.InputActionMap.html) as fields directly inside `MonoBehaviour` components.
77
66
78
67
```CSharp
79
68
usingUnityEngine;
@@ -88,49 +77,18 @@ public class ExampleScript : MonoBehaviour
88
77
89
78
The result is similar to using an Actions defined in the Input Actions editor, except the Actions are defined in the GameObject's properties and saved as Scene or Prefab data, instead of in a dedicated Asset.
90
79
91
-
When you embed actions in a MonoBehaviour and assign that MonoBehaviour to a GameObject, the GameObject's Inspector window displays an interface similar to the Actions Asset window, which allows you to set up the bindings for those actions. For example:
80
+
When you embed actions like this, by defining serialized InputAction fields in a MonoBehaviour, the GameObject's Inspector window displays an interface similar to the Actions column of the [Actions Editor](./ActionsEditor.md), which allows you to set up the bindings for those actions. For example:
The visual editors work similarly to the [Input Actions editor](ActionsEditor.md).
96
-
97
84
* To add or remove Actions or Bindings, click the Add (+) or Remove (-) icon in the header.
98
85
* To edit Bindings, double-click them.<br>
99
86
* To edit Actions, double-click them in an Action Map, or click the gear icon on individual Action properties.<br>
100
87
* You can also right-click entries to bring up a context menu, and you can drag them. Hold the Alt key and drag an entry to duplicate it.
101
88
102
89
Unlike the project-wide actions in the Project Settings window, you must manually enable and disable Actions and Action Maps that are embedded in MonoBehaviour components.
103
90
104
-
```CSharp
105
-
publicclassMyBehavior : MonoBehaviour
106
-
{
107
-
// ...
108
-
109
-
voidAwake()
110
-
{
111
-
fireAction.performed+=OnFire;
112
-
lookAction.performed+=OnLook;
113
-
114
-
gameplayActions["fire"].performed+=OnFire;
115
-
}
116
-
117
-
voidOnEnable()
118
-
{
119
-
fireAction.Enable();
120
-
lookAction.Enable();
121
-
122
-
gameplayActions.Enable();
123
-
}
124
-
125
-
voidOnDisable()
126
-
{
127
-
fireAction.Disable();
128
-
lookAction.Disable();
129
-
130
-
gameplayActions.Disable();
131
-
}
132
-
}
133
-
```
91
+
When you use this workflow, the serialised action configurations are stored with the parent GameObject as part of the scene, opposite to being serialised with an Action Asset. This can be useful if you want to bundle the control bindings and behaviour together in a single monobehaviour or prefab, so it can be distributed together. However, this can also make it harder to organize your full set of control bindings if they are distributed across multiple prefabs or scenes.
134
92
135
93
### Loading Actions from JSON
136
94
@@ -177,7 +135,13 @@ Any action that you create in this way during Play mode do not persist in the In
177
135
178
136
## Enabling actions
179
137
180
-
Actions defined in the [Input Actions editor](ActionsEditor.md) are enabled by default and ready to use. For actions defined elsewhere, such as in your own code or in Action Assets, they begin in a disabled state, and you must enable them before they will respond to input. You can enable them individually, or as a group by enabling the Action Map which contains them.
138
+
Actions have an **enabled** state, meaning you can enable or disable them to suit different situations.
139
+
140
+
If you have an Action Asset assigned as [project-wide](./ProjectWideActions.md), the actions it contains are enabled by default and ready to use.
141
+
142
+
For actions defined elsewhere, such as in an Action Asset not assigned as project-wide, or defined your own code, they begin in a disabled state, and you must enable them before they will respond to input.
143
+
144
+
You can enable actions individually, or as a group by enabling the Action Map which contains them.
Copy file name to clipboardExpand all lines: Packages/com.unity.inputsystem/Documentation~/ActionsEditor.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,31 @@
1
1
---
2
2
uid: input-system-configuring-input
3
3
---
4
-
# Configuring Input
4
+
# Configuring Input with the Actions Editor
5
5
6
-
The **Input Actions Editor** allows you to configure [Input Actions](Actions.md) and their associated [Bindings](ActionBindings.md) and [Control Schemes](ActionBindings.md#control-schemes).
6
+
The **Input Actions Editor** allows you to edit [Action Assets](ActionAssets.md), which contain a saved configuration of [Input Actions](Actions.md) and their associated [Bindings](ActionBindings.md).
7
7
8
-
Open the Input Actions settings by going to **Edit** > **Project Settings** > **Input System Package** > **Input Actions**
8
+
It allows you to group collections of Actions into [Action Maps](ActionsEditor.html#configure-action-maps), which represent different input scenarios in your project (such as UI navigation, gameplay, etc.)
9
9
10
-

11
-
*The Input Actions editor in the Project Settings window*
10
+
It also alows you to define [Control Schemes](ActionBindings.md#control-schemes) which are a way to enable or disable a set of devices, or respond to which type of device is being used. This is often useful if you want to customise your UI based on whether your users are using mouse, keyboard, or gamepad as their chosen input.
12
11
13
-
The Input Action editor is divided into three panels (marked A, B & C above).
12
+
### Action Assets and Project-Wide Actions
14
13
15
-
### The default Actions
14
+
The typical workflow for most projects is to have a single Action Asset, which is assigned as the **project-wide actions**. If you have not yet created and assigned an Actions Asset as the project-wide actions, the recommended workflow is to do this first. Read more about [project-wide actions](ProjectWideActions.md).
16
15
17
-
The Input System comes pre-configured with some default Actions such as "Move", "Jump", and more, which suit many common app and game scenarios. They are configured to read input most types of input controller such as Keyboard, Mouse, Gamepad, Touchscreen and XR.
16
+
### Opening the Actions Editor
18
17
19
-
When you first open the Input Actions Editor, you can see the default action maps and actions displayed.
18
+
The **Input Actions Editor** is an editor window displayed when you open an Action Asset by double-clicking it.
20
19
21
-
These default actions mean that in many cases, you can start scripting with the Input System without any configuration by referring to the names of the default actions that are already configured for you. You can also rename and reconfigure the default actions, or delete these default configurations to suit your needs.
20
+
It is also displayed in the Project Settings window under **Edit** > **Project Settings** > **Input System Package** if you have an Action Asset assigned as project-wide.
22
21
23
-
If you’d like to delete all the default actions so that you can start from an empty configuration, you don’t need to delete the individual actions one-by-one. You can delete the default Action Maps, which deletes all the Actions contained in those maps in one go.
22
+

23
+
*The Input Actions editor, displaying the default actions*
24
24
25
25
### The Actions Editor panels
26
26
27
+
The Input Actions editor is divided into three panels (marked A, B & C above).
28
+
27
29
|Name|Description|
28
30
|-|-|
29
31
|**(A) Action Maps**|Displays the list of currently defined Action Maps. Each Action Map is a collection of Actions that you can enable or disable together as a group.|
@@ -43,7 +45,8 @@ If you’d like to delete all the default actions so that you can start from an
43
45
* To rename an existing Action, either long-click the name, or right-click the Action Map and select __Rename__ from the context menu.
44
46
* To delete an existing Action, either right-click it and select __Delete__ from the context menu.
45
47
* To duplicate an existing Action, either right-click it and select __Duplicate__ from the context menu.
46
-
* To re-order actions in the list, drag an action and drop it to its new position in the list. **Note:** The order of actions in this window is for visual convenience only, and does not affect the order in which the actions are triggered in your code. If multiple actions are performed in the same frame, the order in which they are reported by the input system is undefined. To avoid problems, you should not write code that assumes they will be reported in a particular order.
Copy file name to clipboardExpand all lines: Packages/com.unity.inputsystem/Documentation~/Concepts.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,3 +16,4 @@ This page introduces the basic concepts that relate to working with the Input Sy
16
16
|[**Action Map**](ActionsEditor.html#configure-action-maps)| Action Maps allow you to organise Actions into groups which represent specific situations where a set of actions make sense together. You can simultaneously enable or disable all Actions in an action map, so it is useful to group Actions in Action Maps by the context in which they are relevant. For example, you might have one action map for controlling a player, and another for interacting with your game's UI.|
17
17
|[**Binding**](ActionBindings.html)| A connection defined between an **Action** and specific device controls. For example, your "Move" action might have bindings to the arrow keys and WSAD keys on the keyboard, and the left stick on a joypad, and the primary 2D axis on a VR controller. Multiple bindings like this means your game can accept cross-platform input. |
18
18
|[**Your Action Code**](RespondingToActions.md)| The part of your script which is executed based on the actions you have configured. In your code, you can use references to actions to either read the current value or state of the action (also known as "polling"), or set up a callback to call your own method when actions are performed.|
19
+
|[**Action Asset**](ActionAssets.md)| An asset type which contains a saved configuration of Action Maps, Actions and Bindings. You can specify one Action Asset in your project as the [project-wide actions](ProjectWideActions.md), which allows you to easily reference those actions in code by using [`InputSystem.actions`](../api/UnityEngine.InputSystem.InputSystem.html). |
0 commit comments