Class InputSystemUIInputModule | Input System | 1.0.2
docs.unity3d.com
    Show / Hide Table of Contents

    Class InputSystemUIInputModule

    Input module that takes its input from InputAction.

    Inheritance
    Object
    UnityEngine.EventSystems.UIBehaviour
    UnityEngine.EventSystems.BaseInputModule
    InputSystemUIInputModule
    Inherited Members
    UnityEngine.EventSystems.BaseInputModule.m_RaycastResultCache
    UnityEngine.EventSystems.BaseInputModule.m_InputOverride
    UnityEngine.EventSystems.BaseInputModule.FindFirstRaycast(System.Collections.Generic.List<UnityEngine.EventSystems.RaycastResult>)
    UnityEngine.EventSystems.BaseInputModule.DetermineMoveDirection(System.Single, System.Single)
    UnityEngine.EventSystems.BaseInputModule.DetermineMoveDirection(System.Single, System.Single, System.Single)
    UnityEngine.EventSystems.BaseInputModule.FindCommonRoot(UnityEngine.GameObject, UnityEngine.GameObject)
    UnityEngine.EventSystems.BaseInputModule.HandlePointerExitAndEnter(UnityEngine.EventSystems.PointerEventData, UnityEngine.GameObject)
    UnityEngine.EventSystems.BaseInputModule.GetAxisEventData(System.Single, System.Single, System.Single)
    UnityEngine.EventSystems.BaseInputModule.GetBaseEventData()
    UnityEngine.EventSystems.BaseInputModule.ShouldActivateModule()
    UnityEngine.EventSystems.BaseInputModule.DeactivateModule()
    UnityEngine.EventSystems.BaseInputModule.UpdateModule()
    UnityEngine.EventSystems.BaseInputModule.IsModuleSupported()
    UnityEngine.EventSystems.BaseInputModule.input
    UnityEngine.EventSystems.BaseInputModule.inputOverride
    UnityEngine.EventSystems.BaseInputModule.eventSystem
    UnityEngine.EventSystems.UIBehaviour.Start()
    UnityEngine.EventSystems.UIBehaviour.IsActive()
    UnityEngine.EventSystems.UIBehaviour.OnValidate()
    UnityEngine.EventSystems.UIBehaviour.Reset()
    UnityEngine.EventSystems.UIBehaviour.OnRectTransformDimensionsChange()
    UnityEngine.EventSystems.UIBehaviour.OnBeforeTransformParentChanged()
    UnityEngine.EventSystems.UIBehaviour.OnTransformParentChanged()
    UnityEngine.EventSystems.UIBehaviour.OnDidApplyAnimationProperties()
    UnityEngine.EventSystems.UIBehaviour.OnCanvasGroupChanged()
    UnityEngine.EventSystems.UIBehaviour.OnCanvasHierarchyChanged()
    UnityEngine.EventSystems.UIBehaviour.IsDestroyed()
    Namespace: UnityEngine.InputSystem.UI
    Syntax
    public class InputSystemUIInputModule : BaseInputModule
    Remarks

    This UI input module has the advantage over other such modules that it doesn't have to know what devices and types of devices input is coming from. Instead, the actions hide the actual sources of input from the module.

    Properties

    actionsAsset

    Declaration
    public InputActionAsset actionsAsset { get; set; }
    Property Value
    Type Description
    InputActionAsset

    cancel

    An InputAction delivering a float button value that determines when ICancelHandler is triggered.

    Declaration
    public InputActionReference cancel { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    The events generated from this input will be received by UnityEngine.EventSystems.ICancelHandler.

    This action together with move and submit form the sources for navigation-style UI input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("move");
    var submitAction = map.AddAction("submit");
    var cancelAction = map.AddAction("cancel");
    
    moveAction.AddBinding("<Gamepad>/*stick");
    moveAction.AddBinding("<Gamepad>/dpad");
    submitAction.AddBinding("<Gamepad>/buttonSouth");
    cancelAction.AddBinding("<Gamepad>/buttonEast");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).move =
        InputActionReference.Create(moveAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).submit =
        InputActionReference.Create(submitAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).cancelAction =
        InputActionReference.Create(cancelAction);
    See Also
    move
    submit

    deselectOnBackgroundClick

    Whether to clear the current selection when a click happens that does not hit any GameObject.

    Declaration
    public bool deselectOnBackgroundClick { get; set; }
    Property Value
    Type Description
    Boolean

    If true (default), clicking outside of any GameObject will reset the current selection.

    Remarks

    By toggling this behavior off, background clicks will keep the current selection. I.e. EventSystem.currentSelectedGameObject will not be changed.

    leftClick

    An InputAction delivering a float button value that determines whether the left button of a pointer is pressed.

    Declaration
    public InputActionReference leftClick { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    Clicks on this button will use UnityEngine.EventSystems.PointerEventData.InputButton.Left for UnityEngine.EventSystems.PointerEventData.button.

    Together with point, rightClick, middleClick, and scrollWheel, this forms the basis for pointer-type UI input.

    Note that together with point, this action is necessary for a pointer to be functional. The other clicks and scrollWheel are optional, however.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("scroll");
    var clickAction = map.AddAction("click");
    
    pointAction.AddBinding("<Mouse>/position");
    pointAction.AddBinding("<Touchscreen>/touch*/position");
    
    clickAction.AddBinding("<Mouse>/leftButton");
    clickAction.AddBinding("<Touchscreen>/touch*/press");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point =
        InputActionReference.Create(pointAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).leftClick =
        InputActionReference.Create(clickAction);
    See Also
    rightClick
    middleClick
    scrollWheel
    point

    middleClick

    An InputAction delivering a float button value that determines whether the middle button of a pointer is pressed.

    Declaration
    public InputActionReference middleClick { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    Clicks on this button will use UnityEngine.EventSystems.PointerEventData.InputButton.Middle for UnityEngine.EventSystems.PointerEventData.button.

    Together with leftClick, rightClick, scrollWheel, and point, this forms the basis for pointer-type UI input.

    Note that the action is optional. A pointer is fully functional with just point and leftClick alone.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("scroll");
    var leftClickAction = map.AddAction("leftClick");
    var middleClickAction = map.AddAction("middleClick");
    
    pointAction.AddBinding("<Mouse>/position");
    pointAction.AddBinding("<Touchscreen>/touch*/position");
    
    leftClickAction.AddBinding("<Mouse>/leftButton");
    leftClickAction.AddBinding("<Touchscreen>/touch*/press");
    
    middleClickAction.AddBinding("<Mouse>/middleButton");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point =
        InputActionReference.Create(pointAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).leftClick =
        InputActionReference.Create(leftClickAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).middleClick =
        InputActionReference.Create(middleClickAction);
    See Also
    leftClick
    rightClick
    scrollWheel
    point

    move

    An InputAction delivering a Vector2 2D motion vector used for sending UnityEngine.EventSystems.AxisEventData navigation events.

    Declaration
    public InputActionReference move { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    The events generated from this input will be received by UnityEngine.EventSystems.IMoveHandler.OnMove(UnityEngine.EventSystems.AxisEventData).

    This action together with submit and cancel form the sources for navigation-style UI input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("move");
    var submitAction = map.AddAction("submit");
    var cancelAction = map.AddAction("cancel");
    
    moveAction.AddBinding("<Gamepad>/*stick");
    moveAction.AddBinding("<Gamepad>/dpad");
    submitAction.AddBinding("<Gamepad>/buttonSouth");
    cancelAction.AddBinding("<Gamepad>/buttonEast");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).move =
        InputActionReference.Create(moveAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).submit =
        InputActionReference.Create(submitAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).cancelAction =
        InputActionReference.Create(cancelAction);
    See Also
    submit
    cancel

    moveRepeatDelay

    Delay in seconds between an initial move action and a repeated move action while move is actuated.

    Declaration
    public float moveRepeatDelay { get; set; }
    Property Value
    Type Description
    Single
    Remarks

    While move is being held down, the input module will first wait for moveRepeatDelay seconds after the first actuation of move and then trigger a move event every moveRepeatRate seconds.

    See Also
    moveRepeatRate
    UnityEngine.EventSystems.AxisEventData

    moveRepeatRate

    Delay in seconds between repeated move actions while move is actuated.

    Declaration
    public float moveRepeatRate { get; set; }
    Property Value
    Type Description
    Single
    Remarks

    While move is being held down, the input module will first wait for moveRepeatDelay seconds after the first actuation of move and then trigger a move event every moveRepeatRate seconds.

    Note that a maximum of one UnityEngine.EventSystems.AxisEventData will be sent per frame. This means that even if multiple time increments of the repeat delay have passed since the last update, only one move repeat event will be generated.

    See Also
    moveRepeatDelay
    UnityEngine.EventSystems.AxisEventData

    point

    An InputAction delivering a Vector2 2D screen position used as a cursor for pointing at UI elements.

    Declaration
    public InputActionReference point { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    The values read from this action determine UnityEngine.EventSystems.PointerEventData.position and UnityEngine.EventSystems.PointerEventData.delta.

    Together with leftClick, rightClick, middleClick, and scrollWheel, this forms the basis for pointer-type UI input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("Point");
    
    pointAction.AddBinding("<Mouse>/position");
    pointAction.AddBinding("<Touchscreen>/touch*/position");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point =
        InputActionReference.Create(pointAction);
    See Also
    leftClick
    rightClick
    middleClick
    scrollWheel

    pointerBehavior

    How to deal with the presence of pointer-type input from multiple devices.

    Declaration
    public UIPointerBehavior pointerBehavior { get; set; }
    Property Value
    Type Description
    UIPointerBehavior

    Wh

    rightClick

    An InputAction delivering a float" button value that determines whether the right button of a pointer is pressed.

    Declaration
    public InputActionReference rightClick { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    Clicks on this button will use UnityEngine.EventSystems.PointerEventData.InputButton.Right for UnityEngine.EventSystems.PointerEventData.button.

    Together with leftClick, middleClick, scrollWheel, and point, this forms the basis for pointer-type UI input.

    Note that the action is optional. A pointer is fully functional with just point and leftClick alone.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("scroll");
    var leftClickAction = map.AddAction("leftClick");
    var rightClickAction = map.AddAction("rightClick");
    
    pointAction.AddBinding("<Mouse>/position");
    pointAction.AddBinding("<Touchscreen>/touch*/position");
    
    leftClickAction.AddBinding("<Mouse>/leftButton");
    leftClickAction.AddBinding("<Touchscreen>/touch*/press");
    
    rightClickAction.AddBinding("<Mouse>/rightButton");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point =
        InputActionReference.Create(pointAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).leftClick =
        InputActionReference.Create(leftClickAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).rightClick =
        InputActionReference.Create(rightClickAction);
    See Also
    leftClick
    middleClick
    scrollWheel
    point

    scrollWheel

    An InputAction delivering a Vector2 scroll wheel value used for sending UnityEngine.EventSystems.PointerEventData events.

    Declaration
    public InputActionReference scrollWheel { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    The values read from this action determine UnityEngine.EventSystems.PointerEventData.scrollDelta.

    Together with leftClick, rightClick, middleClick, and point, this forms the basis for pointer-type UI input.

    Note that the action is optional. A pointer is fully functional with just point and leftClick alone.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("scroll");
    var scrollAction = map.AddAction("scroll");
    
    pointAction.AddBinding("<Mouse>/position");
    pointAction.AddBinding("<Touchscreen>/touch*/position");
    
    scrollAction.AddBinding("<Mouse>/scroll");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).point =
        InputActionReference.Create(pointAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).scrollWheel =
        InputActionReference.Create(scrollAction);
    See Also
    leftClick
    rightClick
    middleClick
    point

    submit

    An InputAction delivering a float button value that determines when ISubmitHandler is triggered.

    Declaration
    public InputActionReference submit { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    The events generated from this input will be received by UnityEngine.EventSystems.ISubmitHandler.

    This action together with move and cancel form the sources for navigation-style UI input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var pointAction = map.AddAction("move");
    var submitAction = map.AddAction("submit");
    var cancelAction = map.AddAction("cancel");
    
    moveAction.AddBinding("<Gamepad>/*stick");
    moveAction.AddBinding("<Gamepad>/dpad");
    submitAction.AddBinding("<Gamepad>/buttonSouth");
    cancelAction.AddBinding("<Gamepad>/buttonEast");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).move =
        InputActionReference.Create(moveAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).submit =
        InputActionReference.Create(submitAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).cancelAction =
        InputActionReference.Create(cancelAction);
    See Also
    move
    cancel

    trackedDeviceDragThresholdMultiplier

    Scales the drag threshold of EventSystem for tracked devices to make selection easier.

    Declaration
    public float trackedDeviceDragThresholdMultiplier { get; set; }
    Property Value
    Type Description
    Single

    trackedDeviceOrientation

    An InputAction delivering a Quaternion value reflecting the orientation of TrackedDevices. In combination with trackedDevicePosition, this is used to determine the transform of tracked devices from which to raycast into the UI scene.

    Declaration
    public InputActionReference trackedDeviceOrientation { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    trackedDeviceOrientation and trackedDevicePosition together replace point for UI input from TrackedDevice. Other than that, UI input for tracked devices is no different from "normal" pointer-type input. This means that leftClick, rightClick, middleClick, and scrollWheel can all be used for tracked device input like for regular pointer input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var positionAction = map.AddAction("position");
    var orientationAction = map.AddAction("orientation");
    var clickAction = map.AddAction("click");
    
    positionAction.AddBinding("<TrackedDevice>/devicePosition");
    orientationAction.AddBinding("<TrackedDevice>/deviceRotation");
    clickAction.AddBinding("<TrackedDevice>/trigger");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).trackedDevicePosition =
        InputActionReference.Create(positionAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).trackedDeviceOrientation =
        InputActionReference.Create(orientationAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).leftClick =
        InputActionReference.Create(clickAction);
    See Also
    trackedDevicePosition

    trackedDevicePosition

    An InputAction delivering a Vector3 value reflecting the position of TrackedDevices. In combination with trackedDeviceOrientation, this is used to determine the transform of tracked devices from which to raycast into the UI scene.

    Declaration
    public InputActionReference trackedDevicePosition { get; set; }
    Property Value
    Type Description
    InputActionReference
    Remarks

    trackedDeviceOrientation and trackedDevicePosition together replace point for UI input from TrackedDevice. Other than that, UI input for tracked devices is no different from "normal" pointer-type input. This means that leftClick, rightClick, middleClick, and scrollWheel can all be used for tracked device input like for regular pointer input.

    var asset = ScriptableObject.Create<InputActionAsset>();
    var map = asset.AddActionMap("UI");
    var positionAction = map.AddAction("position");
    var orientationAction = map.AddAction("orientation");
    var clickAction = map.AddAction("click");
    
    positionAction.AddBinding("<TrackedDevice>/devicePosition");
    orientationAction.AddBinding("<TrackedDevice>/deviceRotation");
    clickAction.AddBinding("<TrackedDevice>/trigger");
    
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).trackedDevicePosition =
        InputActionReference.Create(positionAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).trackedDeviceOrientation =
        InputActionReference.Create(orientationAction);
    ((InputSystemUIInputModule)EventSystem.current.currentInputModule).leftClick =
        InputActionReference.Create(clickAction);
    See Also
    trackedDeviceOrientation

    Methods

    ActivateModule()

    Called by EventSystem when the input module is made current.

    Declaration
    public override void ActivateModule()
    Overrides
    UnityEngine.EventSystems.BaseInputModule.ActivateModule()

    Awake()

    Declaration
    protected override void Awake()
    Overrides
    UnityEngine.EventSystems.UIBehaviour.Awake()

    IsPointerOverGameObject(Int32)

    Check whether the given pointer or touch is currently hovering over a GameObject.

    Declaration
    public override bool IsPointerOverGameObject(int pointerOrTouchId)
    Parameters
    Type Name Description
    Int32 pointerOrTouchId

    ID of the pointer or touch. Meaning this should correspond to either PointerEventData.pointerId or touchId. The pointer ID generally corresponds to the deviceId of the pointer device. An exception to this are touches as a Touchscreen may have multiple pointers (one for each active finger). For touch, you can use the touchId of the touch.

    To check whether any pointer is over a GameObject, simply pass a negative value such as -1.

    Returns
    Type Description
    Boolean

    True if the given pointer is currently hovering over a GameObject.

    Overrides
    UnityEngine.EventSystems.BaseInputModule.IsPointerOverGameObject(System.Int32)
    Remarks

    The result is true if the given pointer has caused an IPointerEnter event to be sent to a GameObject.

    This method can be invoked via EventSystem.current.IsPointerOverGameObject.

    // In general, the pointer ID corresponds to the device ID:
    EventSystem.current.IsPointerOverGameObject(XRController.leftHand.deviceId);
    EventSystem.current.IsPointerOverGameObject(Mouse.current.deviceId);
    
    // For touch input, pass the ID of a touch:
    EventSystem.current.IsPointerOverGameObject(Touchscreen.primaryTouch.touchId.ReadValue());
    
    // But can also pass the ID of the entire Touchscreen in which case the result
    // is true if any touch is over a GameObject:
    EventSystem.current.IsPointerOverGameObject(Touchscreen.current.deviceId);
    
    // Finally, any negative value will be interpreted as "any pointer" and will
    // return true if any one pointer is currently over a GameObject:
    EventSystem.current.IsPointerOverGameObject(-1);
    EventSystem.current.IsPointerOverGameObject(); // Equivalent.
    See Also
    touchId
    deviceId

    OnDestroy()

    Declaration
    protected override void OnDestroy()
    Overrides
    UnityEngine.EventSystems.UIBehaviour.OnDestroy()

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    UnityEngine.EventSystems.BaseInputModule.OnDisable()

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    UnityEngine.EventSystems.BaseInputModule.OnEnable()

    Process()

    Declaration
    public override void Process()
    Overrides
    UnityEngine.EventSystems.BaseInputModule.Process()
    In This Article
    • Properties
      • actionsAsset
      • cancel
      • deselectOnBackgroundClick
      • leftClick
      • middleClick
      • move
      • moveRepeatDelay
      • moveRepeatRate
      • point
      • pointerBehavior
      • rightClick
      • scrollWheel
      • submit
      • trackedDeviceDragThresholdMultiplier
      • trackedDeviceOrientation
      • trackedDevicePosition
    • Methods
      • ActivateModule()
      • Awake()
      • IsPointerOverGameObject(Int32)
      • OnDestroy()
      • OnDisable()
      • OnEnable()
      • Process()
    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