docs.unity3d.com
    Show / Hide Table of Contents

    Class OnScreenStick

    A stick control displayed on screen and moved around by touch or other pointer input.

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    OnScreenControl
    OnScreenStick
    Inherited Members
    OnScreenControl.controlPath
    OnScreenControl.control
    OnScreenControl.SendValueToControl<TValue>(TValue)
    OnScreenControl.SentDefaultValueToControl()
    OnScreenControl.OnEnable()
    OnScreenControl.OnDisable()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, Component)
    Component.TryGetComponent<T>(T)
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType(Type)
    Object.ToString()
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.InputSystem.OnScreen
    Syntax
    [AddComponentMenu("Input/On-Screen Stick")]
    [HelpURL("https://docs.unity3d.com/Packages/com.unity.inputsystem@1.7/manual/OnScreen.html#on-screen-sticks")]
    public class OnScreenStick : OnScreenControl, IPointerDownHandler, IPointerUpHandler, IDragHandler, IEventSystemHandler
    Remarks

    The OnScreenStick works by simulating events from the device specified in the controlPath property. Some parts of the Input System, such as the PlayerInput component, can be set up to auto-switch to a new device when input from them is detected. When a device is switched, any currently running inputs from the previously active device are cancelled. In the case of OnScreenStick, this can mean that the UnityEngine.EventSystems.IPointerUpHandler.OnPointerUp(UnityEngine.EventSystems.PointerEventData) method will be called and the stick will jump back to center, even though the pointer input has not physically been released.

    To avoid this situation, set the useIsolatedInputActions property to true. This will create a set of local Input Actions to drive the stick that are not cancelled when device switching occurs.

    Properties

    behaviour

    Defines how the onscreen stick will move relative to it's origin and the press position.

    Declaration
    public OnScreenStick.Behaviour behaviour { get; set; }
    Property Value
    Type Description
    OnScreenStick.Behaviour

    controlPathInternal

    Declaration
    protected override string controlPathInternal { get; set; }
    Property Value
    Type Description
    String
    Overrides
    OnScreenControl.controlPathInternal

    dynamicOriginRange

    Defines the circular region where the onscreen control may have it's origin placed.

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

    This only applies if behaviour is set to ExactPositionWithDynamicOrigin. When the first press is within this region, then the control will appear at that position and have it's origin of motion placed there. Otherwise, if pressed outside of this region the control will ignore it. This property defines the radius of the circular region. The center point being defined by the component position in the scene.

    movementRange

    The distance from the onscreen control's center of origin, around which the control can move.

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

    useIsolatedInputActions

    Prevents stick interactions from getting cancelled due to device switching.

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

    This property is useful for scenarios where the active device switches automatically based on the most recently actuated device. A common situation where this happens is when using a PlayerInput component with Auto-switch set to true. Imagine a mobile game where an on-screen stick simulates the left stick of a gamepad device. When the on-screen stick is moved, the Input System will see an input event from a gamepad and switch the active device to it. This causes any active actions to be cancelled, including the pointer action driving the on screen stick, which results in the stick jumping back to the center as though it had been released.

    In isolated mode, the actions driving the stick are not cancelled because they are unique Input Action instances that don't share state with any others.

    Methods

    OnDrag(PointerEventData)

    Callback to handle OnDrag UI events.

    Declaration
    public void OnDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData)

    OnPointerDown(PointerEventData)

    Callback to handle OnPointerDown UI events.

    Declaration
    public void OnPointerDown(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IPointerDownHandler.OnPointerDown(UnityEngine.EventSystems.PointerEventData)

    OnPointerUp(PointerEventData)

    Callback to handle OnPointerUp UI events.

    Declaration
    public void OnPointerUp(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IPointerUpHandler.OnPointerUp(UnityEngine.EventSystems.PointerEventData)

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • behaviour
      • controlPathInternal
      • dynamicOriginRange
      • movementRange
      • useIsolatedInputActions
    • Methods
      • OnDrag(PointerEventData)
      • OnPointerDown(PointerEventData)
      • OnPointerUp(PointerEventData)
    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