Skip to content

DOCF-6396 - Processor content model re-org #2123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions Packages/com.unity.inputsystem/Documentation~/Processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,12 @@ uid: input-system-processors
---
# Processors

An Input Processor takes a value and returns a processed result for it. The received value and result value must be of the same type. For example, you can use a [clamp](#clamp) Processor to clamp values from a control to a certain range.

>__Note__: To convert received input values into different types, see [composite Bindings](ActionBindings.md#composite-bindings).

* [Using Processors](#using-processors)
* [Processors on Bindings](#processors-on-bindings)
* [Processors on Actions](#processors-on-actions)
* [Processors on Controls](#processors-on-controls)
* [Predefined Processors](#predefined-processors)
* [Clamp](#clamp)
* [Invert](#invert)
* [Invert Vector 2](#invert-vector-2)
* [Invert Vector 3](#invert-vector-3)
* [Normalize](#normalize)
* [Normalize Vector 2](#normalize-vector-2)
* [Normalize Vector 3](#normalize-vector-3)
* [Scale](#scale)
* [Scale Vector 2](#scale-vector-2)
* [Scale Vector 3](#scale-vector-3)
* [Axis deadzone](#axis-deadzone)
* [Stick deadzone](#stick-deadzone)
* [Writing custom Processors](#writing-custom-processors)



Use an input processor to apply processing to input values and return the result. For example, you can use a [clamp](built-in-processors.md#clamp) processor to clamp values to within a certain range.

|Topic|Description|
|-|-|
|[Introduction to processors](introduction-to-processors.md) |Learn what processors can do to alter input values, and how they interact with bindings, actions, and controls. |
|[Built-in processors](built-in-processors.md) | Explore the processors that come built into the Input System. |
|[Write custom processors](write-custom-processors.md) | Create and register your own processors for use with bindings, actions, and controls. |
|[Add processors to bindings and actions](add-processors-bindings-actions.md) |Add processors to individual bindings, or to all bindings on an action, via the Editor or via code. |
|[Add processors to controls](add-processors-controls.md) | Add processors to specific control inputs, including custom controls. |
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@
* [Controls schemes](control-schemes.md)
* [Interactions](interactions.md)
* [Processors](processors.md)
* [Configure sctions](configure-actions.md)
* [Introduction to processors](introduction-to-processors.md)
* [Built-in processors](built-in-processors.md)
* [Write custom processors](write-custom-processors.md)
* [Add processors to bindings and actions](add-processors-bindings-actions.md)
* [Add processors to controls](add-processors-controls.md)
* [Input Actions Editor reference](actions-editor.md)
* [Input Actions Editor window reference](input-actions-editor-window-reference.md)
* [Action Properties panel reference](action-properties-panel-reference.md)
Expand All @@ -84,7 +88,6 @@
* [Write custom interactions](write-custom-interactions.md)
* [Devices](Devices.md)
* [Controls](controls.md)
* [Processors](Processors.md)
* [Player Input Component](player-input-component.md)
* [Player Input Manager Component](PlayerInputManager.md)
* [Input settings](Settings.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Add processors to bindings and actions

To add a processor to an [action](actions.md) or [binding](ActionBindings.md) via the Input Actions Editor:

1. Select the action or binding you want to add processors to. The Properties panel opens in the right pane of the window.
1. In the Properties panel, navigate to the **Processors** foldout. Select the **Add (+)** icon on the header to open a list of all available processors that match your control type.
1. From the drop-down list, select a processor type. A processor of that type appears in the __Processors__ foldout.
1. In the __Processors__ foldout, edit any parameters of the processor.

<br/>![An example of the Processors foldout in the Properties panel, displaying processors called Stick Deadzone and Scale Vactor 2](Images/BindingProcessors.png)

To remove a processor, select the **Remove (-)** icon next to it. You can also use the up and down arrows to change the order of processors. This affects the order in which the system processes values.

To add a processor to an action or binding via code, use the following code examples as templates:

**Actions:**

```CSharp
var action = new InputAction(processors: "invertVector2(invertX=false)");
```

**Bindings:**

```CSharp
var action = new InputAction();
action.AddBinding("<Gamepad>/leftStick")
.WithProcessor("invertVector2(invertX=false)");
```

>[!NOTE]
>The received value and result value must be of the same type. To convert received input values into different types, see [composite Bindings](ActionBindings.md#composite-bindings).
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Add processors to controls

The Input System automatically adds processors to a Control during device creation if they're specified in the Control's [layout](layouts.md).

You can't add processors to existing Controls after they've been created. You can only add processors to Controls when you're [creating custom devices](Devices.md#creating-custom-devices).

If you're using a layout generated by the Input System from a [state struct](Devices.md#step-1-the-state-struct) using [`InputControlAttributes`](../api/UnityEngine.InputSystem.Layouts.InputControlAttribute.html), you can specify the processors you want to use via the [`processors`](../api/UnityEngine.InputSystem.Layouts.InputControlAttribute.html#UnityEngine_InputSystem_Layouts_InputControlAttribute_processors) property of the attribute, like this:

```CSharp
public struct MyDeviceState : IInputStateTypeInfo
{
public FourCC format => return new FourCC('M', 'Y', 'D', 'V');

// Add an axis deadzone to the Control to ignore values
// smaller then 0.2, as our Control does not have a stable
// resting position.
[InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")]
public short axis;
}
```

If you [create a layout from JSON](layouts.md#layout-from-json), you can specify processors on your Controls like this:

```json
{
"name" : "MyDevice",
"extend" : "Gamepad", // Or some other thing
"controls" : [
{
"name" : "axis",
"layout" : "Axis",
"offset" : 4,
"format" : "FLT",
"processors" : "AxisDeadzone(min=0.2)"
}
]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Built-in Processors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this page? it's repeating information that's already in the API docs.

I'd be tempted to bin it and add something to the intro doc that's like:

## Built in processors

The Input System package comes with a set of built-in processors, defined in the `Processors` class, which you can use with [bindings](ActionBindings.md), [actions](actions.md) and [controls](controls.md). For a list of processors, refer to the [`Processors` API documentation](../api/UnityEngine.InputSystem.Processors.html)

@duckets what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to have a much smaller simpler page with a list or table of the built-in processors, each with a single line describing what they are and a link to the API.

Also need to check that the API description is at last as good as the description from the manual, and replace if not - for example i looked at "Invert Vector 3" and the manual says:

Inverts the values from a Control (that is, multiplies the values by -1). Inverts the x axis of the vector if invertX is true, the y axis if invertY is true, and the z axis if invertZ is true.

Whereas the API says:

Inverts the x and/or y and/or z channel of a Vector3.

The manual content is better, so we should replace the API text with that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ben's suggestions works for me.

There is some information in this page that isn't in the API docs, and I"m not sure if it's more appropriate for the user manual or the API docs - specifically I'm talking about the paragraphs in lines 112 and 113. What would you suggest for those?


The Input System package comes with a set of built-in Processors, which you can use with [bindings](ActionBindings.md), [actions](actions.md) and [controls](controls.md).


|**Processor name**|**Description**|**Operand type**|**Parameters**|
|---|---|---|---|
|[`Clamp`](../api/UnityEngine.InputSystem.Processors.ClampProcessor.html)|Clamps input values to the [`min`..`max`] range.|`float`|<ul><li>`float min`</li><li>`float max`</li></ul>|
|[`Invert`](../api/UnityEngine.InputSystem.Processors.InvertProcessor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1).|`float`|None|
|[`InvertVector2`](../api/UnityEngine.InputSystem.Processors.InvertVector2Processor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1). Inverts the x-axis of the vector if `invertX` is true, and the y-axis if `invertY` is true.|`Vector2`|<ul><li>`bool invertX`</li><li>`bool invertY`</li></ul>|
|[`Invert Vector 3`](../api/UnityEngine.InputSystem.Processors.InvertVector3Processor.html)|Inverts the values from a Control (that is, multiplies the values by &minus;1). Inverts the x-axis of the vector if `invertX` is true, the y-axis if `invertY` is true, and the z-axis if `invertZ` is true.|`Vector3`|<ul><li>`bool invertX`</li><li>`bool invertY`</li><li>`bool invertZ`</li></ul>|
|[`Normalize`](../api/UnityEngine.InputSystem.Processors.NormalizeProcessor.html)|Normalizes input values in the range [`min`..`max`] to unsigned normalized form [0..1] if `min` is >= `zero`, and to signed normalized form [-1..1] if `min` < `zero`.|`float`|<ul><li>`float min`</li><li>`float max`</li><li>`float zero`</li></ul>|
|[`NormalizeVector2`](../api/UnityEngine.InputSystem.Processors.NormalizeVector2Processor.html)|Normalizes input vectors to be of unit length (1). This is the same as calling `Vector2.normalized`.|`Vector2`|None|
|[`NormalizeVector3`](../api/UnityEngine.InputSystem.Processors.NormalizeVector3Processor.html)|Normalizes input vectors to be of unit length (1). This is the same as calling `Vector3.normalized`.|`Vector3`|None|
|[`Scale`](../api/UnityEngine.InputSystem.Processors.ScaleProcessor.html)|Multiplies all input values by `factor`.|`float`|`float factor`|
|[`ScaleVector2`](../api/UnityEngine.InputSystem.Processors.ScaleVector2Processor.html)|Multiplies all input values by `x` along the x-axis and by `y` along the y-axis.|`Vector2`|<ul><li>`float x`</li><li>`float y`</li></ul>|
|[`ScaleVector3`](../api/UnityEngine.InputSystem.Processors.ScaleVector3Processor.html)|Multiplies all input values by `x` along the x-axis, by `y` along the y-axis, and by `z` along the z-axis.|`Vector3`|<ul><li>`float x`</li><li>`float y`</li><li>`float z`</li></ul>|
|[`AxisDeadzone`](../api/UnityEngine.InputSystem.Processors.AxisDeadzoneProcessor.html)|Scales the values of a Control so that any value with an absolute value smaller than `min` is 0, and any value with an absolute value larger than `max` is 1 or &minus;1.<br/><br/>Many Controls don't have a precise resting point (that is, they don't always report exactly 0 when the Control is in the center). Using the `min` value on a deadzone Processor avoids unintentional input from such Controls. Also, some Controls don't consistently report their maximum values when moving the axis all the way. Using the `max` value on a deadzone Processor ensures that you always get the maximum value in such cases.|`float`|<ul><li>`float min`</li><li>`float max`</li></ul>|
|[`StickDeadzone`](../api/UnityEngine.InputSystem.Processors.StickDeadzoneProcessor.html)|Scales the values of a Vector2 Control, such as a stick, so that any input vector with a magnitude smaller than `min` results in (0,0), and any input vector with a magnitude greater than `max` is normalized to length 1.<br/><br/>Many Controls don't have a precise resting point (that is, they don't always report exactly 0,0 when the Control is in the center). Using the `min` value on a deadzone Processor avoids unintentional input from such Controls. Also, some Controls don't consistently report their maximum values when moving the axis all the way. Using the `max` value on a deadzone Processor ensures that you always get the maximum value in such cases.|`Vector2`|<ul><li>`float min`</li><li>`float max`</li></ul>

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Introduction to processors

Input processors apply processing to input values, and return the result. The Input System’s [built-in processors](built-in-processors.md) can apply value clamping, scaling, normalization, inversion, and deadzones. You can also create [custom processors](write-custom-processors.md) to apply additional data processing to input values.

You can install processors on [bindings](ActionBindings.md), [actions](actions.md) or [controls](controls.md). The Input System [registers](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_RegisterProcessor__1_System_String_) each processor with a unique name. This means that if you need to replace an existing processor, you need to register the new processor under the name of the existing processor.

Processors can have boolean, integer, and floating-point number parameters. When created in data such as [bindings](./ActionBindings.md), processors are described as strings that look like function calls.

For example, the following string references the processor registered as "scale" and sets its "factor" parameter to a floating-point value of 2.5:

```CSharp
"scale(factor=2.5)"
```

Multiple processors can be chained together. The Input System processes them in the order they appear in code. For example, the following string inverts a value, then normalizes [0..10] values to [0..1]:

```CSharp
"invert,normalize(min=0,max=10)"
```

## Processors on bindings and actions

When you create bindings for your [actions](actions.md), you can choose to add processors to the bindings. These process the values from the controls they bind to, before the system applies them to the action value. For example, you could invert the `Vector2` values from the controls along the Y axis before passing the values to the associated action.

Processors on actions work the same way, but affect all bindings on an action.

If there are processors on both the binding and the action, the Input System processes the processors from the binding first.

To apply a processor to a binding or action, refer to [Add processors to bindings and actions](add-processors-bindings-actions.md).

## Processors on controls

You can have any number of processors directly on an [`InputControl`](../api/UnityEngine.InputSystem.InputControl.html), which then process the values read from the Control. Whenever you call [`ReadValue`](../api/UnityEngine.InputSystem.InputControl-1.html#UnityEngine_InputSystem_InputControl_1_ReadValue) on a Control, all processors on that Control process the value before it gets returned to you. You can use [`ReadUnprocessedValue`](../api/UnityEngine.InputSystem.InputControl-1.html#UnityEngine_InputSystem_InputControl_1_ReadUnprocessedValue) on a Control to bypass the processors.

The devices that the Input System supports out of the box already have some useful processors added to their controls by default. For example, sticks on gamepads have a [Stick Deadzone](built-in-processors.md#stick-deadzone) processor.

To apply a processor to a control, refer to [Add processors to controls](add-processors-controls.md)
108 changes: 0 additions & 108 deletions Packages/com.unity.inputsystem/Documentation~/predefined-processors.md

This file was deleted.

This file was deleted.

Loading