43 lines
2.2 KiB
Markdown
43 lines
2.2 KiB
Markdown
---
|
|
uid: input-system-add-processors-controls
|
|
---
|
|
|
|
# Add processors to controls
|
|
|
|
You can have any number of Processors directly on an [`InputControl`](xref:UnityEngine.InputSystem.InputControl), which then process the values read from the Control. Whenever you call [`ReadValue`](xref:UnityEngine.InputSystem.InputControl`1) on a Control, all Processors on that Control process the value before it gets returned to you. You can use [`ReadUnprocessedValue`](xref:UnityEngine.InputSystem.InputControl`1) on a Control to bypass the Processors.
|
|
|
|
The Input System 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, so you can only add Processors to Controls when you're [creating custom devices](custom-devices.md). The devices that the Input System supports out of the box already have some useful Processors added on their Controls. For instance, sticks on gamepads have a [Stick Deadzone](built-in-processors.md) Processor.
|
|
|
|
If you're using a layout generated by the Input System from a [state struct](step-1-state-struct.md) using [`InputControlAttributes`](xref:UnityEngine.InputSystem.Layouts.InputControlAttribute), you can specify the Processors you want to use with the [`processors`](xref:UnityEngine.InputSystem.Layouts.InputControlAttribute) 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](add-layout-from-json.md), you can specify Processors on your Controls like this:
|
|
|
|
```CSharp
|
|
{
|
|
"name" : "MyDevice",
|
|
"extend" : "Gamepad", // Or some other thing
|
|
"controls" : [
|
|
{
|
|
"name" : "axis",
|
|
"layout" : "Axis",
|
|
"offset" : 4,
|
|
"format" : "FLT",
|
|
"processors" : "AxisDeadzone(min=0.2)"
|
|
}
|
|
]
|
|
}
|
|
```
|