docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputControl<TValue>

    Base class for input controls with a specific value type.

    Inheritance
    object
    InputControl
    InputControl<TValue>
    AxisControl
    DoubleControl
    IntegerControl
    QuaternionControl
    TouchControl
    TouchPhaseControl
    Vector2Control
    Vector3Control
    BoneControl
    EyesControl
    PoseControl
    Inherited Members
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    Syntax
    public abstract class InputControl<TValue> : InputControl where TValue : struct
    Type Parameters
    Name Description
    TValue

    Type of value captured by the control. Note that this does not mean that the control has to store data in the given value format. A control that captures float values, for example, may be stored in state as byte values instead.

    Properties

    value

    Returns the current value of the control after processors have been applied.

    Declaration
    public ref readonly TValue value { get; }
    Property Value
    Type Description
    TValue

    The controls current value.

    Remarks

    This can only be called on devices that have been added to the system (added).

    If internal feature "USE_READ_VALUE_CACHING" is enabled, then this property implements caching to avoid applying processors when the underlying control has not changed. With this in mind, be aware of processors that use global state, such as the AxisDeadzoneProcessor. Unless the control unprocessed value has been changed, input system settings changed or ApplyParameterChanges() invoked, the processors will not run and calls to value will return the same result as previous calls.

    If a processor requires to be run on every read, override cachingPolicy property in the processor and set it to EvaluateOnEveryRead.

    To improve debugging try setting "PARANOID_READ_VALUE_CACHING_CHECKS" internal feature flag to check if cache value is still consistent.

    Also note that this property returns the result as ref readonly. If custom control states are in use, i.e. any controls not shipped with the Input System package, be careful of accidental defensive copies https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-defensive-copies.

    See Also
    ReadValue()

    valueSizeInBytes

    Size in bytes of values that the control returns.

    Declaration
    public override int valueSizeInBytes { get; }
    Property Value
    Type Description
    int
    Overrides
    InputControl.valueSizeInBytes
    Remarks

    The type can be determined with valueType.

    valueType

    Returns the underlying value type of this control.

    Declaration
    public override Type valueType { get; }
    Property Value
    Type Description
    Type

    Type of values produced by the control.

    Overrides
    InputControl.valueType
    Remarks

    This is the type of values that are returned when reading the current value of a control or when reading a value of a control from an event with ReadValueFromStateAsObject(void*). The size can be determined with valueSizeInBytes.

    Methods

    CompareValue(void*, void*)

    Compared values in state buffers.

    Declaration
    public override bool CompareValue(void* firstStatePtr, void* secondStatePtr)
    Parameters
    Type Name Description
    void* firstStatePtr

    The first state buffer to read value from.

    void* secondStatePtr

    The second state buffer to read value from.

    Returns
    Type Description
    bool

    True if the buffer values match. False if they differ.

    Overrides
    InputControl.CompareValue(void*, void*)

    FinishSetup()

    Perform final initialization tasks after the control hierarchy has been put into place.

    Declaration
    protected override void FinishSetup()
    Overrides
    InputControl.FinishSetup()
    Remarks

    This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.

    Examples
      public class MyDevice : InputDevice
                            {
                                public ButtonControl button { get; private set; }
                                public AxisControl axis { get; private set; }
    
                                protected override void OnFinishSetup()
                                {
                                    // Cache controls in getters.
                                    button = GetChildControl("button");
                                    axis = GetChildControl("axis");
                                }
                            }
    

    ProcessValue(TValue)

    Applies all control processors to the passed value.

    Declaration
    public TValue ProcessValue(TValue value)
    Parameters
    Type Name Description
    TValue value

    value to run processors on.

    Returns
    Type Description
    TValue

    The processed value.

    Remarks

    Applies all control processors to the passed value.

    ProcessValue(ref TValue)

    Applies all control processors to the passed value.

    Declaration
    public void ProcessValue(ref TValue value)
    Parameters
    Type Name Description
    TValue value

    value to run processors on.

    Remarks

    Use this overload when your state struct is large to avoid creating copies of the state.

    ReadDefaultValue()

    Get the control's default value.

    Declaration
    public TValue ReadDefaultValue()
    Returns
    Type Description
    TValue

    The control's default value.

    Remarks

    This is not necessarily equivalent to default(TValue). A control's default value is determined by reading its value from the default state (defaultStatePtr) which in turn is determined from settings in the control's registered layout (defaultState).

    ReadUnprocessedValue()

    Read value from control

    Declaration
    public TValue ReadUnprocessedValue()
    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    This is the locally cached value. Use ReadUnprocessedValueFromStateWithCaching(void*)to get the uncached version.

    See Also
    value

    ReadUnprocessedValueFromState(void*)

    Read value from provided statePtr.

    Declaration
    public abstract TValue ReadUnprocessedValueFromState(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State pointer to read from.

    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    Read value from provided statePtr without any caching.

    See Also
    value

    ReadUnprocessedValueFromStateWithCaching(void*)

    Read value from provided statePtr. Try cache result if possible.

    Declaration
    public TValue ReadUnprocessedValueFromStateWithCaching(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State pointer to read from.

    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    If statePtr is "currentStatePtr", then read will be done via unprocessedValue property to improve performance.

    See Also
    value

    ReadValue()

    Returns the current value of the control after processors have been applied.

    Declaration
    public TValue ReadValue()
    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    This can only be called on devices that have been added to the system (added).

    If internal feature "USE_READ_VALUE_CACHING" is enabled, then this property implements caching to avoid applying processors when the underlying control has not changed. With this in mind, be aware of processors that use global state, such as the AxisDeadzoneProcessor. Unless the control unprocessed value has been changed, input system settings changed or ApplyParameterChanges() invoked, the processors will not run and calls to value will return the same result as previous calls.

    If a processor requires to be run on every read, override cachingPolicy property in the processor and set it to EvaluateOnEveryRead.

    To improve debugging try setting "PARANOID_READ_VALUE_CACHING_CHECKS" internal feature flag to check if cache value is still consistent. https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-defensive-copies.

    See Also
    value

    ReadValueFromBufferAsObject(void*, int)

    Read the control's final, processed value from the given buffer and return the value as an object.

    Declaration
    public override object ReadValueFromBufferAsObject(void* buffer, int bufferSize)
    Parameters
    Type Name Description
    void* buffer

    Buffer to read the value from.

    int bufferSize

    Size of buffer in bytes, which must be large enough to store the value.

    Returns
    Type Description
    object

    The control's value as stored in buffer.

    Overrides
    InputControl.ReadValueFromBufferAsObject(void*, int)
    Remarks

    Read the control's final, processed value from the given buffer and return the value as an object.

    This method allocates GC memory and should not be used during normal gameplay operation.

    Exceptions
    Type Condition
    ArgumentNullException

    buffer is null.

    ArgumentException

    bufferSize is smaller than the size of the value to be read.

    See Also
    ReadValueFromStateAsObject(void*)

    ReadValueFromPreviousFrame()

    Get the control's value from the previous frame (previousFrameStatePtr).

    Declaration
    public TValue ReadValueFromPreviousFrame()
    Returns
    Type Description
    TValue

    The control's value in the previous frame.

    ReadValueFromState(void*)

    Get the control's default value.

    Declaration
    public TValue ReadValueFromState(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State containing the control's stateBlock.

    Returns
    Type Description
    TValue

    The control's default value.

    Remarks

    This is not necessarily equivalent to default(TValue). A control's default value is determined by reading its value from the default state (defaultStatePtr) which in turn is determined from settings in the control's registered layout (defaultState).

    ReadValueFromStateAsObject(void*)

    Read the control's final, processed value from the given state and return the value as an object.

    Declaration
    public override object ReadValueFromStateAsObject(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State to read the value for the control from.

    Returns
    Type Description
    object

    The control's value as stored in statePtr.

    Overrides
    InputControl.ReadValueFromStateAsObject(void*)
    Remarks

    Read the control's final, processed value from the given state and return the value as an object.

    This method allocates GC memory and should not be used during normal gameplay operation.

    Exceptions
    Type Condition
    ArgumentNullException

    statePtr is null.

    See Also
    ReadValueFromStateIntoBuffer(void*, void*, int)

    ReadValueFromStateIntoBuffer(void*, void*, int)

    Read the control's final, processed value from the given state and store it in the given buffer.

    Declaration
    public override void ReadValueFromStateIntoBuffer(void* statePtr, void* bufferPtr, int bufferSize)
    Parameters
    Type Name Description
    void* statePtr

    State to read the value for the control from.

    void* bufferPtr

    Buffer to store the value in.

    int bufferSize

    Size of bufferPtr in bytes. Must be at least valueSizeInBytes. If it is smaller, ArgumentException will be thrown.

    Overrides
    InputControl.ReadValueFromStateIntoBuffer(void*, void*, int)
    Exceptions
    Type Condition
    ArgumentNullException

    statePtr is null, or bufferPtr is null.

    ArgumentException

    bufferSize is smaller than valueSizeInBytes.

    See Also
    ReadValueFromStateAsObject(void*)
    WriteValueFromBufferIntoState(void*, int, void*)

    ReadValueFromStateWithCaching(void*)

    Read value from provided statePtr and apply processors. Try cache result if possible.

    Declaration
    public TValue ReadValueFromStateWithCaching(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State pointer to read from.

    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    If statePtr is "currentStatePtr", then read will be done via value property to improve performance.

    See Also
    value

    WriteValueFromBufferIntoState(void*, int, void*)

    Read a value from the given memory and store it as state.

    Declaration
    public override void WriteValueFromBufferIntoState(void* bufferPtr, int bufferSize, void* statePtr)
    Parameters
    Type Name Description
    void* bufferPtr

    Memory containing value, to store into the state.

    int bufferSize

    Size of bufferPtr in bytes. Must be at least valueSizeInBytes.

    void* statePtr

    State containing the control's stateBlock. Will receive the state as converted from the given value.

    Overrides
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    Remarks

    Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.

    Exceptions
    Type Condition
    NotSupportedException

    The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector).

    See Also
    ReadValueFromStateIntoBuffer(void*, void*, int)
    WriteValueFromObjectIntoState(object, void*)

    WriteValueFromObjectIntoState(object, void*)

    Read a value object and store it as state in the given memory.

    Declaration
    public override void WriteValueFromObjectIntoState(object value, void* statePtr)
    Parameters
    Type Name Description
    object value

    Value for the control to store in the state.

    void* statePtr

    State containing the control's stateBlock. Will receive the state as converted from the given value.

    Overrides
    InputControl.WriteValueFromObjectIntoState(object, void*)
    Remarks

    Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.

    Exceptions
    Type Condition
    NotSupportedException

    The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector).

    See Also
    WriteValueFromBufferIntoState(void*, int, void*)

    WriteValueIntoState(TValue, void*)

    Write a value into state at the given memory.

    Declaration
    public virtual void WriteValueIntoState(TValue value, void* statePtr)
    Parameters
    Type Name Description
    TValue value

    Value for the control to store in the state.

    void* statePtr

    State containing the control's stateBlock. Will receive the state as converted from the given value.

    Remarks

    Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.

    Exceptions
    Type Condition
    NotSupportedException

    The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector).

    See Also
    WriteValueFromBufferIntoState(void*, int, void*)

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.QueueValueChange<TValue>(InputControl<TValue>, TValue, double)
    InputControlExtensions.ReadUnprocessedValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr)
    InputControlExtensions.ReadUnprocessedValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr, out TValue)
    InputControlExtensions.ReadValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr)
    InputControlExtensions.ReadValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr, out TValue)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl<TValue>, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl<TValue>, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl<TValue>, TValue, void*)
    InputControlExtensions.WriteValueIntoState<TValue, TState>(InputControl<TValue>, TValue, ref TState)
    In This Article
    • Properties
      • value
      • valueSizeInBytes
      • valueType
    • Methods
      • CompareValue(void*, void*)
      • FinishSetup()
      • ProcessValue(TValue)
      • ProcessValue(ref TValue)
      • ReadDefaultValue()
      • ReadUnprocessedValue()
      • ReadUnprocessedValueFromState(void*)
      • ReadUnprocessedValueFromStateWithCaching(void*)
      • ReadValue()
      • ReadValueFromBufferAsObject(void*, int)
      • ReadValueFromPreviousFrame()
      • ReadValueFromState(void*)
      • ReadValueFromStateAsObject(void*)
      • ReadValueFromStateIntoBuffer(void*, void*, int)
      • ReadValueFromStateWithCaching(void*)
      • WriteValueFromBufferIntoState(void*, int, void*)
      • WriteValueFromObjectIntoState(object, void*)
      • WriteValueIntoState(TValue, void*)
    • Extension Methods
    Back to top
    Copyright © 2025 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)