Skip to content

Commit 7b18140

Browse files
ducketsekcohlyndon-unity
authored
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]>
1 parent c746539 commit 7b18140

28 files changed

+142
-135
lines changed

Packages/com.unity.inputsystem/Documentation~/ActionAssets.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@ uid: input-system-action-assets
33
---
44
# Input Action Assets
55

6-
* [Creating Action Assets](#creating-input-action-assets)
7-
* [Editing Action Assets](#editing-input-action-assets)
8-
* [Using Action Assets](#using-input-action-assets)
6+
- [Creating Input Action Assets](#creating-input-action-assets)
7+
- [Editing Input Action Assets](#editing-input-action-assets)
8+
- [Using Input Action Assets](#using-input-action-assets)
9+
- [Type-safe C# API Generation](#type-safe-c-api-generation)
910

1011
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.
1112

12-
### Why use an Input Action Asset instead of configuring actions in 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.
1314

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.
1516

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.
2317

2418
## Creating Input Action Assets
2519

@@ -34,6 +28,11 @@ The Actions Editor which opens is identical to the [Actions Editor in the Projec
3428

3529
## Using Input Action Assets
3630

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+
3736
### Auto-generating script code for Actions
3837

3938
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()
118117
}
119118
```
120119

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.

Packages/com.unity.inputsystem/Documentation~/Actions.md

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ Actions also make it simpler to create a system that lets your players [customiz
2929

3030
## Overview
3131

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:
3333

34-
|Class|Description|
34+
|API name|Description|
3535
|-----|-----------|
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).|
3737
|[`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).|
3838
|[`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).|
3939
|[`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
4646

4747
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.
4848

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.
5450

5551
### Creating Actions using the Action editor
5652

@@ -62,18 +58,11 @@ For information on how to create and edit Input Actions in the editor, see the [
6258

6359
# Other ways to create Actions
6460

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.
7362

7463
### Creating Actions by declaring them in MonoBehaviours
7564

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.
7766

7867
```CSharp
7968
using UnityEngine;
@@ -88,49 +77,18 @@ public class ExampleScript : MonoBehaviour
8877

8978
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.
9079

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:
9281

9382
![MyBehavior Inspector](Images/Workflow-EmbeddedActionsInspector.png)
9483

95-
The visual editors work similarly to the [Input Actions editor](ActionsEditor.md).
96-
9784
* To add or remove Actions or Bindings, click the Add (+) or Remove (-) icon in the header.
9885
* To edit Bindings, double-click them.<br>
9986
* To edit Actions, double-click them in an Action Map, or click the gear icon on individual Action properties.<br>
10087
* 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.
10188

10289
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.
10390

104-
```CSharp
105-
public class MyBehavior : MonoBehaviour
106-
{
107-
// ...
108-
109-
void Awake()
110-
{
111-
fireAction.performed += OnFire;
112-
lookAction.performed += OnLook;
113-
114-
gameplayActions["fire"].performed += OnFire;
115-
}
116-
117-
void OnEnable()
118-
{
119-
fireAction.Enable();
120-
lookAction.Enable();
121-
122-
gameplayActions.Enable();
123-
}
124-
125-
void OnDisable()
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.
13492

13593
### Loading Actions from JSON
13694

@@ -177,7 +135,13 @@ Any action that you create in this way during Play mode do not persist in the In
177135

178136
## Enabling actions
179137

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.
181145

182146
```CSharp
183147
// Enable a single action.

Packages/com.unity.inputsystem/Documentation~/ActionsEditor.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
---
22
uid: input-system-configuring-input
33
---
4-
# Configuring Input
4+
# Configuring Input with the Actions Editor
55

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).
77

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.)
99

10-
![image alt text](./Images/ProjectSettingsInputActions.png)
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.
1211

13-
The Input Action editor is divided into three panels (marked A, B & C above).
12+
### Action Assets and Project-Wide Actions
1413

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).
1615

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
1817

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.
2019

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.
2221

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+
![image alt text](./Images/ActionsEditorCallout.png)
23+
*The Input Actions editor, displaying the default actions*
2424

2525
### The Actions Editor panels
2626

27+
The Input Actions editor is divided into three panels (marked A, B & C above).
28+
2729
|Name|Description|
2830
|-|-|
2931
|**(A)&nbsp;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
4345
* To rename an existing Action, either long-click the name, or right-click the Action Map and select __Rename__ from the context menu.
4446
* To delete an existing Action, either right-click it and select __Delete__ from the context menu.
4547
* 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.
48+
*
49+
4750

4851
## Action type and Control type
4952

Packages/com.unity.inputsystem/Documentation~/Concepts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ This page introduces the basic concepts that relate to working with the Input Sy
1616
|[**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.|
1717
|[**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. |
1818
|[**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). |
38.6 KB
Loading
41.8 KB
Loading
20 KB
Loading
-93.4 KB
Loading
36.3 KB
Loading
69.3 KB
Loading

0 commit comments

Comments
 (0)