docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputProcessor<TValue>

    A processor that conditions/transforms input values.

    Inheritance
    object
    InputProcessor
    InputProcessor<TValue>
    AxisDeadzoneProcessor
    ClampProcessor
    EditorWindowSpaceProcessor
    InvertProcessor
    InvertVector2Processor
    InvertVector3Processor
    NormalizeProcessor
    NormalizeVector2Processor
    NormalizeVector3Processor
    ScaleProcessor
    ScaleVector2Processor
    ScaleVector3Processor
    StickDeadzoneProcessor
    Inherited Members
    InputProcessor.cachingPolicy
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    Syntax
    public abstract class InputProcessor<TValue> : InputProcessor where TValue : struct
    Type Parameters
    Name Description
    TValue

    Type of value to be processed. Only InputControls that use the same value type will be compatible with the processor.

    Remarks

    Each InputControl can have a stack of processors assigned to it.

    Note that processors CANNOT be stateful. If you need processing that requires keeping mutating state over time, use InputActions. All mutable state needs to be kept in the central state buffers.

    However, processors can have configurable parameters. Every public field on a processor object can be set using "parameters" in JSON or by supplying parameters through the processors field.

    // To register the processor, call
    //
    //    InputSystem.RegisterProcessor<ScalingProcessor>("scale");
    //
    public class ScalingProcessor : InputProcessor<float>
    {
        // This field can be set as a parameter. See examples below.
        // If not explicitly configured, will have its default value.
        public float factor = 2.0f;
    public float Process(float value, InputControl control)
    {
        return value * factor;
    }
    
    }
    // Use processor in JSON:
    const string json = @"
    {
    ""name"" : ""MyDevice"",
    ""controls"" : [
    { ""name"" : ""axis"", ""layout"" : ""Axis"", ""processors"" : ""scale(factor=4)"" }
    ]
    }
    ";
    // Use processor on C# state struct:
    public struct MyDeviceState : IInputStateTypeInfo
    {
    [InputControl(layout = "Axis", processors = "scale(factor=4)"]
    public float axis;
    }

    See InputParameterEditor<TObject> for how to define custom parameter editing UIs for processors.

    Methods

    Process(void*, int, InputControl)

    Process an input value stored in the given memory buffer.

    Declaration
    public override void Process(void* buffer, int bufferSize, InputControl control)
    Parameters
    Type Name Description
    void* buffer

    Memory buffer containing the input value. Must be at least large enough to hold one full value as indicated by bufferSize.

    int bufferSize

    Size (in bytes) of the value inside buffer.

    InputControl control

    Optional control that the value originated from. Must have the same value type that the processor has.

    Overrides
    InputProcessor.Process(void*, int, InputControl)
    Remarks

    This method allows processing values of arbitrary size without allocating memory on the GC heap.

    See Also
    RegisterProcessor(Type, string)

    Process(TValue, InputControl)

    Process the given value and return the result.

    Declaration
    public abstract TValue Process(TValue value, InputControl control)
    Parameters
    Type Name Description
    TValue value

    Input value to process.

    InputControl control

    Control that the value originally came from. This can be null if the value did not originate from a control. This can be the case, for example, if the processor sits on a composite binding (InputBindingComposite) as composites are not directly associated with controls but rather source their values through their child bindings.

    Returns
    Type Description
    TValue

    Processed input value.

    Remarks

    The implementation of this method must not be stateful.

    See Also
    RegisterProcessor(Type, string)

    ProcessAsObject(object, InputControl)

    Process an input value, given as an object, and return the processed value as an object.

    Declaration
    public override object ProcessAsObject(object value, InputControl control)
    Parameters
    Type Name Description
    object value

    A value matching the processor's value type.

    InputControl control

    Optional control that the value originated from. Must have the same value type that the processor has.

    Returns
    Type Description
    object

    A processed value based on value.

    Overrides
    InputProcessor.ProcessAsObject(object, InputControl)
    Remarks

    This method allocates GC heap memory. To process values without allocating GC memory, it is necessary to either know the value type of a processor at compile time and call Process(TValue, InputControl) directly or to use Process(void*, int, InputControl) instead and process values in raw memory buffers.

    See Also
    RegisterProcessor(Type, string)

    See Also

    RegisterProcessor(Type, string)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Methods
      • Process(void*, int, InputControl)
      • Process(TValue, InputControl)
      • ProcessAsObject(object, InputControl)
    • See Also
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)