Class InputSystemUIInputModule
Input module that takes its input from input actions.
Inheritance
Inherited Members
Namespace: UnityEngine .InputSystem .UI
Assembly: Unity.InputSystem.dll
Syntax
[HelpURL("https://docs.unity3d.com/Packages/com.unity.inputsystem@1.10/manual/UISupport.html#setting-up-ui-input")]
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.
When adding this component from code (such as through GameObject.AddComponent
), the
resulting module will automatically have a set of default input actions assigned to it
(see Assign
Properties
actionsAsset
Declaration
public InputActionAsset actionsAsset { get; set; }
Property Value
Type | Description |
---|---|
Input |
cancel
An Inputfloat
button value that determines when ICancelHandler
is triggered.
Declaration
public InputActionReference cancel { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
The events generated from this input will be received by Unity
This action together with move and submit form the sources for navigation-style UI input.
This action should have its type set to Button.
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
cursorLockBehavior
Where to position the pointer when the cursor is locked.
Declaration
public InputSystemUIInputModule.CursorLockBehavior cursorLockBehavior { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
By default, the pointer is positioned at -1, -1 in screen space when the cursor is locked. This has implications
for using ray casters like Unity
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 |
---|---|
bool | 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 Inputfloat
button value that determines
whether the left button of a pointer is pressed.
Declaration
public InputActionReference leftClick { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
Clicks on this button will use Unity
Together with point, right
Note that together with point, this action is necessary for a pointer to be functional. The other clicks
and scroll
This action should have its type set to Pass"Button"
.
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
middleClick
An Inputfloat
button value that determines
whether the middle button of a pointer is pressed.
Declaration
public InputActionReference middleClick { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
Clicks on this button will use Unity
Together with left
Note that the action is optional. A pointer is fully functional with just point
and left
This action should have its type set to Pass"Button"
.
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
move
An InputVector2
2D motion vector
used for sending Unity
Declaration
public InputActionReference move { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
The events generated from this input will be received by Unity
This action together with submit and cancel form the sources for navigation-style UI input.
This action should have its type set to Pass"Vector2"
.
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
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 |
---|---|
float |
Remarks
While move is being held down, the input module will first wait for move
See Also
moveRepeatRate
Delay in seconds between repeated move actions while move is actuated.
Declaration
public float moveRepeatRate { get; set; }
Property Value
Type | Description |
---|---|
float |
Remarks
While move is being held down, the input module will first wait for move
Note that a maximum of one Unity
See Also
point
An Input
Declaration
public InputActionReference point { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
The values read from this action determine Unity
Together with left
This action should have its type set to Pass"Vector2"
.
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
pointerBehavior
How to deal with the presence of pointer-type input from multiple devices.
Declaration
public UIPointerBehavior pointerBehavior { get; set; }
Property Value
Type | Description |
---|---|
UIPointer |
Remarks
By default, this is set to Single
The primary effect of this setting is to determine whether the user can concurrently point at more than a single UI element or not. Whenever multiple pointers are allowed, more than one element may have a pointer over it at any one point and thus several elements can be interacted with concurrently.
rightClick
An Inputfloat"
button value that determines
whether the right button of a pointer is pressed.
Declaration
public InputActionReference rightClick { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
Clicks on this button will use Unity
Together with left
Note that the action is optional. A pointer is fully functional with just point
and left
This action should have its type set to Pass"Button"
.
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
scrollDeltaPerTick
A multiplier value that allows you to adjust the scroll wheel speed sent to uGUI (Unity UI) components.
Declaration
public float scrollDeltaPerTick { get; set; }
Property Value
Type | Description |
---|---|
float |
Remarks
This value controls the magnitude of the PointerEventData.scrollDelta value, when the scroll wheel is rotated one tick. It acts as a multiplier, so a value of 1 passes through the original value and behaves the same as the legacy Standalone Input Module.
A value larger than one increases the scrolling speed per tick, and a value less than one decreases the speed.
You can set this to a negative value to invert the scroll direction. A value of zero prevents mousewheel scrolling from working at all.
Note: this has no effect on UI Toolkit content, only uGUI components.
scrollWheel
An InputVector2
scroll wheel value
used for sending Unity
Declaration
public InputActionReference scrollWheel { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
The values read from this action determine Unity
Together with left
Note that the action is optional. A pointer is fully functional with just point
and left
This action should have its type set to Pass"Vector2"
.
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
submit
An Inputfloat
button value that determines when ISubmitHandler
is triggered.
Declaration
public InputActionReference submit { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
The events generated from this input will be received by Unity
This action together with move and cancel form the sources for navigation-style UI input.
This action should have its type set to Button.
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
trackedDeviceDragThresholdMultiplier
Scales the drag threshold of EventSystem
for tracked devices to make selection easier.
Declaration
public float trackedDeviceDragThresholdMultiplier { get; set; }
Property Value
Type | Description |
---|---|
float |
trackedDeviceOrientation
An InputQuaternion
value reflecting the orientation of Tracked
Declaration
public InputActionReference trackedDeviceOrientation { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
tracked
This action should have its type set to Pass"Quaternion"
.
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
An InputVector3
value reflecting the position of Tracked
Declaration
public InputActionReference trackedDevicePosition { get; set; }
Property Value
Type | Description |
---|---|
Input |
Remarks
tracked
This action should have its type set to Pass"Vector3"
.
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
xrTrackingOrigin
A Transform representing the real world origin for tracking devices. This is used to convert real world positions and rotations for Tracked pointers into Unity's global space. When using the XR Interaction Toolkit, this should be pointing to the XR Rig's Transform.
Declaration
public Transform xrTrackingOrigin { get; set; }
Property Value
Type | Description |
---|---|
Transform |
Remarks
This will transform all tracked pointers. If unset, or set to null, the Unity world origin will be used as the basis for all tracked positions and rotations.
Methods
ActivateModule()
Called by EventSystem
when the input module is made current.
Declaration
public override void ActivateModule()
Overrides
AssignDefaultActions()
Declaration
public void AssignDefaultActions()
Awake()
Declaration
protected override void Awake()
Overrides
GetLastRaycastResult(int)
Returns the most recent raycast information for a given pointer or touch.
Declaration
public RaycastResult GetLastRaycastResult(int pointerOrTouchId)
Parameters
Type | Name | Description |
---|---|---|
int | pointerOrTouchId | ID of the pointer or touch. Meaning this should correspond to either
|
Returns
Type | Description |
---|---|
Raycast |
The most recent raycast information. |
Remarks
This method is for the most recent raycast, but depending on when it's called is not guaranteed to be for the current frame.
This method can be used to determine raycast distances and hit information for visualization.
Use Unity
See Also
IsPointerOverGameObject(int)
Check whether the given pointer or touch is currently hovering over a GameObject
.
Declaration
public override bool IsPointerOverGameObject(int pointerOrTouchId)
Parameters
Type | Name | Description |
---|---|---|
int | pointerOrTouchId | ID of the pointer or touch. Meaning this should correspond to either
|
Returns
Type | Description |
---|---|
bool | True if the given pointer is currently hovering over a |
Overrides
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
.
Be aware that this method relies on state set up during UI event processing that happens in EventSystem.Update
,
that is, as part of MonoBehaviour
updates. This step happens after input processing.
Thus, calling this method earlier than that in the frame will make it poll state from last frame.
Calling this method from within an Input
// 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
OnDestroy()
Declaration
protected override void OnDestroy()
Overrides
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Declaration
protected override void OnEnable()
Overrides
Process()
Process the current tick for the module.
Declaration
public override void Process()
Overrides
Reset()
Declaration
protected override void Reset()
Overrides
UnassignActions()
Remove all action assignments, that is actions
Declaration
public void UnassignActions()
Remarks
If the current actions were enabled by the UI input module, they will be disabled in the process.