Class InputControl<TValue>
Base class for input controls with a specific value type.
Inherited Members
Namespace: UnityEngine.InputSystem
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
valueSizeInBytes
Declaration
public override int valueSizeInBytes { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
valueType
Declaration
public override Type valueType { get; }
Property Value
Type | Description |
---|---|
Type |
Overrides
Methods
CompareValue(Void*, Void*)
Declaration
public override bool CompareValue(void *firstStatePtr, void *secondStatePtr)
Parameters
Type | Name | Description |
---|---|---|
Void* | firstStatePtr | |
Void* | secondStatePtr |
Returns
Type | Description |
---|---|
Boolean |
Overrides
FinishSetup()
Declaration
protected override void FinishSetup()
Overrides
ProcessValue(TValue)
Declaration
public TValue ProcessValue(TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value |
Returns
Type | Description |
---|---|
TValue |
ProcessValue(ref TValue)
Applies all control processors to the passed value.
Declaration
public void ProcessValue(ref TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value |
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()
Declaration
public TValue ReadUnprocessedValue()
Returns
Type | Description |
---|---|
TValue |
ReadUnprocessedValueFromState(Void*)
Declaration
public abstract TValue ReadUnprocessedValueFromState(void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
Void* | statePtr |
Returns
Type | Description |
---|---|
TValue |
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 UnityEngine.InputSystem.InputControl`1.unprocessedValue property to improve performance.
See Also
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
ReadValueFromBufferAsObject(Void*, Int32)
Declaration
public override object ReadValueFromBufferAsObject(void *buffer, int bufferSize)
Parameters
Type | Name | Description |
---|---|---|
Void* | buffer | |
Int32 | bufferSize |
Returns
Type | Description |
---|---|
Object |
Overrides
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*)
Declaration
public TValue ReadValueFromState(void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
Void* | statePtr |
Returns
Type | Description |
---|---|
TValue |
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 |
Returns
Type | Description |
---|---|
Object | The control's value as stored in |
Overrides
Remarks
This method allocates GC memory and should not be used during normal gameplay operation.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
See Also
ReadValueFromStateIntoBuffer(Void*, Void*, Int32)
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. |
Int32 | bufferSize | Size of |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentException |
|
See Also
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
WriteValueFromBufferIntoState(Void*, Int32, Void*)
Declaration
public override void WriteValueFromBufferIntoState(void *bufferPtr, int bufferSize, void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
Void* | bufferPtr | |
Int32 | bufferSize | |
Void* | statePtr |
Overrides
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. |
Void* | statePtr | State containing the control's stateBlock. Will receive the state state as converted from the given value. |
Overrides
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
WriteValueIntoState(TValue, Void*)
Declaration
public virtual void WriteValueIntoState(TValue value, void *statePtr)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | |
Void* | statePtr |