-
Notifications
You must be signed in to change notification settings - Fork 325
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
jo-unity
merged 5 commits into
docs-content-model-reorg
from
docf-6396-cm-reorg-processors
Mar 13, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2712617
First draft of processor docs re-org
siobhan-gibson 585a39a
Updates following PR review
siobhan-gibson f02ce76
Merge branch 'docs-content-model-reorg' into docf-6396-cm-reorg-proce…
jo-unity 0044974
Update built-in-processors.md
jo-unity f62c6b1
Merge branch 'docs-content-model-reorg' into docf-6396-cm-reorg-proce…
jo-unity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Packages/com.unity.inputsystem/Documentation~/add-processors-bindings-actions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/> | ||
|
||
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). |
38 changes: 38 additions & 0 deletions
38
Packages/com.unity.inputsystem/Documentation~/add-processors-controls.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
] | ||
} | ||
``` |
20 changes: 20 additions & 0 deletions
20
Packages/com.unity.inputsystem/Documentation~/built-in-processors.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Built-in Processors | ||
|
||
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 −1).|`float`|None| | ||
|[`InvertVector2`](../api/UnityEngine.InputSystem.Processors.InvertVector2Processor.html)|Inverts the values from a Control (that is, multiplies the values by −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 −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 −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> | ||
|
37 changes: 37 additions & 0 deletions
37
Packages/com.unity.inputsystem/Documentation~/introduction-to-processors.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
108
Packages/com.unity.inputsystem/Documentation~/predefined-processors.md
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
Packages/com.unity.inputsystem/Documentation~/processors-on-actions.md
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
@duckets what do you think?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?