Class InputDevice | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class InputDevice

    The root of a control hierarchy.

    Inheritance
    System.Object
    InputControl
    InputDevice
    Gamepad
    Joystick
    Keyboard
    HID
    OculusTrackingReference
    ViveLighthouse
    XRController
    XRHMD
    Pointer
    Sensor
    SteeringWheel
    Inherited Members
    InputControl.ReservedCharacters
    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.Item[String]
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(Void*)
    InputControl.WriteValueFromBufferIntoState(Void*, Int32, Void*)
    InputControl.WriteValueFromObjectIntoState(Object, Void*)
    InputControl.CompareState(Void*, Void*, Void*)
    InputControl.TryGetChildControl(String)
    InputControl.FinishSetup(InputDeviceBuilder)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: UnityEngine.Experimental.Input
    Syntax
    public class InputDevice : InputControl
    Remarks

    Input devices act as the container for control hierarchies. Every hierarchy has to have a device at the root. Devices cannot occur inside of hierarchies.

    Unlike other controls, usages of InputDevices are allowed to be changed on the fly without requiring a change to the device layout (SetDeviceUsage(InputDevice, String)).

    Constructors

    InputDevice()

    Declaration
    public InputDevice()

    Fields

    kInvalidDeviceId

    Declaration
    public const int kInvalidDeviceId = 0
    Field Value
    Type Description
    System.Int32

    Properties

    added

    Whether the device has been added to the system.

    Declaration
    public bool added { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    Input devices can be constructed manually through . Also, they can be removed through RemoveDevice(InputDevice). This property reflects whether the device is currently added to the system.

    Note that devices in disconnectedDevices will all have this property return false.

    See Also
    AddDevice(InputDevice)
    devices

    allControls

    A flattened list of controls that make up the device.

    Declaration
    public ReadOnlyArray<InputControl> allControls { get; }
    Property Value
    Type Description
    ReadOnlyArray<InputControl>
    Remarks

    Does not allocate.

    canRunInBackground

    If true, the device is capable of delivering input while the application is running in the background.

    Declaration
    public bool canRunInBackground { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    Note that by default, even if capable of doing so, devices will not generate input while the application is not focused. To enable the behavior, use runInBackground.

    See Also
    runInBackground

    description

    Metadata describing the device (product name etc.).

    Declaration
    public InputDeviceDescription description { get; }
    Property Value
    Type Description
    InputDeviceDescription
    Remarks

    The description of a device is unchanging over its lifetime and does not comprise data about a device's configuration (which is considered mutable).

    enabled

    Whether the device is currently enabled (i.e. sends and receives events).

    Declaration
    public bool enabled { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    A device that is disabled will not receive events. I.e. events that are being sent to the device will be ignored.

    When disabling a native device, a disable command will also be sent to the runtime. It depends on the specific runtime whether the device command is supported but if it is, the device will be disabled in the runtime and no longer send events. This is especially important for devices such as Sensor that incur both computation and battery consumption overhead while enabled.

    Specific types of devices can choose to start out in disabled state by default. This is generally the case for Sensor to ensure that their overhead is only incurred when actually being used by the application.

    See Also
    EnableDevice(InputDevice)
    DisableDevice(InputDevice)

    id

    Unique numeric ID for the device.

    Declaration
    public int id { get; }
    Property Value
    Type Description
    System.Int32
    Remarks

    This is only assigned once a device has been added to the system. No two devices will receive the same ID and no device will receive an ID that another device used before even if the device was removed.

    IDs are assigned by the input runtime.

    lastUpdateTime

    Timestamp of last state event used to update the device.

    Declaration
    public double lastUpdateTime { get; }
    Property Value
    Type Description
    System.Double
    Remarks

    Events other than StateEvent and DeltaStateEvent will not cause lastUpdateTime to be changed.

    native

    Whether the device comes from the runtime

    Declaration
    public bool native { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    Devices can be discovered when reported by the runtime or they can be added manually through the various AddDevice(InputDevice) APIs. Devices reported by the runtime will return true for this property whereas devices added manually will return false.

    Devices reported by the runtime will usually come from the Unity engine itself.

    remote

    Whether the device is mirrored from a remote input system and not actually present as a "real" device in the local system.

    Declaration
    public bool remote { get; }
    Property Value
    Type Description
    System.Boolean
    See Also
    remoting
    InputRemoting

    updateBeforeRender

    Whether the device requires an extra update before rendering.

    Declaration
    public bool updateBeforeRender { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    The value of this property is determined by in the device's control layout.

    The extra update is necessary for tracking devices that are used in rendering code. For example, the eye transforms of an HMD should be refreshed right before rendering as refreshing only in the beginning of the frame will lead to a noticeable lag.

    See Also
    BeforeRender

    valueSizeInBytes

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

    valueType

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

    wasUpdatedThisFrame

    Declaration
    public bool wasUpdatedThisFrame { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    CompareValue(Void*, Void*)

    Declaration
    public override bool CompareValue(void *firstStatePtr, void *secondStatePtr)
    Parameters
    Type Name Description
    System.Void* firstStatePtr
    System.Void* secondStatePtr
    Returns
    Type Description
    System.Boolean
    Overrides
    InputControl.CompareValue(Void*, Void*)

    ExecuteCommand<TCommand>(ref TCommand)

    Declaration
    public long ExecuteCommand<TCommand>(ref TCommand command)where TCommand : struct, IInputDeviceCommandInfo
    Parameters
    Type Name Description
    TCommand command
    Returns
    Type Description
    System.Int64
    Type Parameters
    Name Description
    TCommand

    MakeCurrent()

    Make this the current device of its type.

    Declaration
    public virtual void MakeCurrent()
    Remarks

    Use this to set static properties that give fast access to the latest device used of a given type (current or and ).

    This functionality is somewhat like a 'pwd' for the semantic paths but one where there can be multiple current working directories, one for each type.

    A device will be made current by the system initially when it is created and subsequently whenever it receives an event.

    OnAdded()

    Declaration
    protected virtual void OnAdded()

    OnRemoved()

    Declaration
    protected virtual void OnRemoved()

    ReadValueFromStateAsObject(Void*)

    Declaration
    public override object ReadValueFromStateAsObject(void *statePtr)
    Parameters
    Type Name Description
    System.Void* statePtr
    Returns
    Type Description
    System.Object
    Overrides
    InputControl.ReadValueFromStateAsObject(Void*)

    ReadValueFromStateIntoBuffer(Void*, Void*, Int32)

    Declaration
    public override void ReadValueFromStateIntoBuffer(void *statePtr, void *bufferPtr, int bufferSize)
    Parameters
    Type Name Description
    System.Void* statePtr
    System.Void* bufferPtr
    System.Int32 bufferSize
    Overrides
    InputControl.ReadValueFromStateIntoBuffer(Void*, Void*, Int32)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023