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
Copy file name to clipboardExpand all lines: Packages/com.unity.inputsystem/Documentation~/Architecture.md
+26-24Lines changed: 26 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,17 @@
1
1
---
2
2
uid: input-system-architecture
3
-
description: Understand how the Input System's low-level and high-level layers turn platform input into actions that your application responds to.
4
3
---
5
4
# Input System architecture
6
5
7
6
Understand how the Input System's low-level and high-level layers turn platform input into actions that your application responds to.
8
7
9
8
The Input System has two layers. The low-level layer receives raw input from the platform-specific back end that ships with Unity, and stores that input as device state in unmanaged memory. The high-level layer interprets that state as controls, actions, and bindings that your application code responds to.
10
9
11
-
This page describes the built-in back end that supplies the input, then the low-level system that stores it, then the high-level system that interprets it.
10
+
The built-in back end supplies the input, the low-level system stores it, and the high-level system interprets it.
12
11
13
12
## The built-in back end
14
13
15
-
The foundation of the Input System is the built-in back-end code. This platform-specific code collects information about the available devices, and the input data from those devices. The code isn't part of the Input System package; it ships with Unity itself, and it has an implementation for each runtime platform that Unity supports.
14
+
The foundation of the Input System is the built-in back-end code. This platform-specific code collects information about the available devices, and the input data from those devices. The code isn't part of the Input System package; it ships with Unity itself, and it has an implementation for each runtime platform that Unity supports.
16
15
17
16
The Input System interfaces with the built-in back end in two ways:
18
17
@@ -33,7 +32,8 @@ The low-level system works as a layered pipeline. The following three diagrams e
33
32
2. The `InputManager` class uses layouts to build devices.
34
33
3. Each device writes its state into input state memory.
35
34
36
-
**Note**: `InputManager` is the Input System class that owns devices and drives updates. It's not the **Input Manager** window, which configures Unity's legacy input settings.
35
+
> [!NOTE]
36
+
> `InputManager` is the Input System class that owns devices and drives updates. It's not the **Input Manager** window, which configures Unity's legacy input settings.
37
37
38
38
The following table describes the color coding that all the diagrams on this page use:
39
39
@@ -55,7 +55,7 @@ The built-in back ends push discovery and state events into the device discovery
55
55
56
56
```mermaid
57
57
flowchart TB
58
-
%% Diagram 1 of 3: platform back ends queue events
Layouts derive from one another. Together with reusable control building blocks, they describe how to build devices and their controls. The `InputManager` class searches these layouts and creates the concrete devices.
94
94
95
-
For example:
95
+
The following examples show how layouts and building blocks relate to one another:
96
96
97
97
- The `Mouse`, `Pen`, and `Touchscreen` layouts all derive from the `Pointer` layout.
98
-
- The PS4 and HID variants of `DualShock` both derive from a shared `DualShock` layout, which itself derives from `Gamepad`.
98
+
- The PS4 and human interface device (HID) variants of `DualShock` both derive from a shared `DualShock` layout, which itself derives from `Gamepad`.
99
99
- Building blocks such as `Stick`, `Axis`, `Button`, and `Dpad` supply the individual controls that each device exposes.
100
100
101
101
```mermaid
102
102
flowchart TB
103
-
%% Diagram 2 of 3: layouts build devices
103
+
%% Diagram 2: layouts build devices
104
104
%% Bands stack top-to-bottom; each band is compact left-to-right.
105
105
106
106
in2>"→ from Diagram 1: the InputManager class"] -.-> InputManager
@@ -159,16 +159,16 @@ flowchart TB
159
159
160
160
Each built device exposes a tree of controls. When state events arrive, the Input System writes the device and control state into input state memory, where each device and control has its own chunk of unmanaged memory.
161
161
162
-
For example:
162
+
The following examples show how devices expose controls:
163
163
164
164
- A `Gamepad` device exposes a `leftStick` control that resolves to the `x`, `y`, `up`, `down`, `left`, and `right` controls.
165
-
- A `Keyboard` device exposes one control for each key.
165
+
- A `Keyboard` device exposes one control for each key.
166
166
167
167
Both devices write into the same input state memory.
168
168
169
169
```mermaid
170
170
flowchart TB
171
-
%% Diagram 3 of 3: devices store their state in memory
171
+
%% Diagram 3: devices store their state in memory
172
172
%% Outer flow is top-to-bottom; subgraphs run left-to-right so controls stay readable.
173
173
in3>"→ from Diagram 2: the built devices"] -.-> GP & KB
174
174
@@ -215,13 +215,13 @@ The high-level system also lets you do the following:
215
215
216
216
Two diagrams describe the high-level system:
217
217
218
-
1.How input flows through the system at runtime.
219
-
1.How you author actions as assets.
218
+
1.The first diagram shows how input flows through the system at runtime.
219
+
1.The second diagram shows how you author actions as assets.
220
220
221
-
Both diagrams show a single player. Each additional player has:
221
+
Both diagrams show a single player. For each additional player, the Input System creates the following objects:
222
222
223
-
-Its own `InputActionState` object.
224
-
- A cloned `InputActionAsset` object with its own device list and binding mask.
223
+
-An `InputActionState` object for that player.
224
+
- A cloned [`InputActionAsset`](xref:UnityEngine.InputSystem.InputActionAsset) object with its own device list and binding mask.
225
225
226
226
### Diagram 4: Runtime input flow
227
227
@@ -230,18 +230,19 @@ At runtime, input reaches your scene through four steps:
230
230
1. The Input System writes a device's control state into input state memory.
231
231
2. A state change monitor notices the change.
232
232
3. The Input System updates the `InputActionState` object.
233
-
4. The resulting action fires a callback on the `PlayerInput` component in the scene.
233
+
4. The resulting action fires a callback on the [`PlayerInput`](xref:UnityEngine.InputSystem.PlayerInput) component in the scene.
234
234
235
235
The following diagram traces those steps for a single control, the space key on a keyboard:
236
236
237
-
1. The keyboard's space control stores its value as one bit of `KeyboardState`.
238
-
1. A `StateEvent` object carrying that state feeds `InputManager.OnUpdate()`, which calls `NotifyControlStateChanged()` on the `InputActionState` object.
239
-
That object holds three arrays: `triggerStates[]`, `bindingStates[]`, and `controls[]`.
237
+
1. The keyboard's space control stores its value as one bit of `KeyboardState`.
238
+
1. A [`StateEvent`](xref:UnityEngine.InputSystem.LowLevel.StateEvent) object carrying that state feeds `InputManager.OnUpdate()`, which calls `NotifyControlStateChanged()` on the `InputActionState` object.
239
+
That object holds three arrays: `triggerStates[]`, `bindingStates[]`, and `controls[]`.
240
240
1. State change monitors update the binding and control arrays.
241
-
1. The trigger array notifies `InputUser`, which calls `OnActionTriggered()` on the `PlayerInput` component.
241
+
1. The trigger array notifies [`InputUser`](xref:UnityEngine.InputSystem.Users.InputUser), which calls `OnActionTriggered()` on the `PlayerInput` component.
242
242
243
243
```mermaid
244
244
flowchart TB
245
+
%% Diagram 4: runtime input flow
245
246
%% ---------- Devices ----------
246
247
Keyboard["Keyboard"] --> space["space"]
247
248
@@ -288,15 +289,16 @@ An `InputActionAsset` object contains action maps, actions, and bindings. At run
288
289
289
290
The following diagram shows an asset named `MyGame.inputactions` that lists `Keyboard` as its device and masks bindings to the `KeyboardMouse` group:
290
291
291
-
1. The asset contains a `gameplay` action map, which contains a `jump` action and two bindings for that action:
292
+
1. The asset contains a `gameplay` action map, which contains a `jump` action and two bindings for that action:
0 commit comments