docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Scrollbar

    A standard scrollbar with a variable sized handle that can be dragged between 0 and 1.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    Selectable
    Scrollbar
    Implements
    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IBeginDragHandler
    IDragHandler
    IInitializePotentialDragHandler
    IEventSystemHandler
    ICanvasElement
    Inherited Members
    Selectable.s_Selectables
    Selectable.s_SelectableCount
    Selectable.allSelectablesArray
    Selectable.allSelectableCount
    Selectable.AllSelectablesNoAlloc(Selectable[])
    Selectable.m_CurrentIndex
    Selectable.navigation
    Selectable.transition
    Selectable.colors
    Selectable.spriteState
    Selectable.animationTriggers
    Selectable.targetGraphic
    Selectable.interactable
    Selectable.image
    Selectable.animator
    Selectable.Awake()
    Selectable.OnCanvasGroupChanged()
    Selectable.IsInteractable()
    Selectable.OnDidApplyAnimationProperties()
    Selectable.OnTransformParentChanged()
    Selectable.Reset()
    Selectable.currentSelectionState
    Selectable.InstantClearState()
    Selectable.DoStateTransition(Selectable.SelectionState, bool)
    Selectable.FindSelectable(Vector3)
    Selectable.IsHighlighted()
    Selectable.IsPressed()
    Selectable.OnPointerEnter(PointerEventData)
    Selectable.OnPointerExit(PointerEventData)
    Selectable.OnSelect(BaseEventData)
    Selectable.OnDeselect(BaseEventData)
    Selectable.Select()
    UIBehaviour.Start()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnBeforeTransformParentChanged()
    UIBehaviour.OnCanvasHierarchyChanged()
    UIBehaviour.IsDestroyed()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    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.transformHandle
    Component.gameObject
    Component.tag
    Object.GetEntityId()
    Object.MemberwiseClone()
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    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, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectsByType(Type)
    Object.FindObjectsByType(Type, FindObjectsInactive)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsByType<T>()
    Object.FindObjectsByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.UI
    Assembly: UnityEngine.UI.dll
    Syntax
    [AddComponentMenu("UI (Canvas)/Scrollbar", 36)]
    [ExecuteAlways]
    [RequireComponent(typeof(RectTransform))]
    public class Scrollbar : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IBeginDragHandler, IDragHandler, IInitializePotentialDragHandler, IEventSystemHandler, ICanvasElement
    Remarks

    The slider component is a Selectable that controls a handle which follow the current value and is sized according to the size property. The anchors of the handle RectTransforms are driven by the Scrollbar. The handle can be a direct child of the GameObject with the Scrollbar, or intermediary RectTransforms can be placed in between for additional control. When a change to the scrollbar value occurs, a callback is sent to any registered listeners of onValueChanged.

    Constructors

    Scrollbar()

    Protected default constructor. Use UnityEngine.GameObject.AddComponent<T>() to add a Scrollbar to a GameObject.

    Declaration
    protected Scrollbar()

    Properties

    direction

    The direction of the scrollbar from minimum to maximum value.

    Declaration
    public Scrollbar.Direction direction { get; set; }
    Property Value
    Type Description
    Scrollbar.Direction

    handleRect

    The RectTransform to use for the handle.

    Declaration
    public RectTransform handleRect { get; set; }
    Property Value
    Type Description
    RectTransform

    numberOfSteps

    The number of steps to use for the value. A value of 0 disables use of steps.

    Declaration
    public int numberOfSteps { get; set; }
    Property Value
    Type Description
    int

    onValueChanged

    Handling for when the scrollbar value is changed.

    Declaration
    public Scrollbar.ScrollEvent onValueChanged { get; set; }
    Property Value
    Type Description
    Scrollbar.ScrollEvent
    Remarks

    Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.

    size

    The size of the scrollbar handle where 1 means it fills the entire scrollbar.

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

    value

    The current value of the scrollbar, between 0 and 1.

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

    Methods

    ClickRepeat(PointerEventData)

    Coroutine that repeatedly scrolls toward the pointer position while the button is held down.

    Declaration
    [Obsolete("Use ClickRepeat(Vector2 screenPosition, Camera camera) instead")]
    protected IEnumerator ClickRepeat(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the held press.

    Returns
    Type Description
    IEnumerator

    An enumerator for the coroutine.

    Remarks

    Obsolete. Please use ClickRepeat(Vector2, Camera) instead.

    ClickRepeat(Vector2, Camera)

    Coroutine function for handling continual press during Scrollbar.OnPointerDown.

    Declaration
    protected IEnumerator ClickRepeat(Vector2 screenPosition, Camera camera)
    Parameters
    Type Name Description
    Vector2 screenPosition

    The screen position to scroll toward.

    Camera camera

    The camera for screen-to-world conversion.

    Returns
    Type Description
    IEnumerator

    An enumerator for the coroutine.

    FindSelectableOnDown()

    Find the selectable object below this one.

    Declaration
    public override Selectable FindSelectableOnDown()
    Returns
    Type Description
    Selectable

    The nearest Selectable below, or null.

    Overrides
    Selectable.FindSelectableOnDown()
    Remarks

    Prevents selection if the Scrollbar moves on the Vertical axis.

    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class Example : MonoBehaviour
                            {
                                public Button startButton;
    
                                // Disables the selectable UI element directly below the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element below the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnDown();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnLeft()

    Find the selectable object to the left of this one.

    Declaration
    public override Selectable FindSelectableOnLeft()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the left, or null.

    Overrides
    Selectable.FindSelectableOnLeft()
    Remarks

    Prevents selection if the Scrollbar moves on the Horizontal axis.

    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly to the left of the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element to the left the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnLeft();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnRight()

    Find the selectable object to the right of this one.

    Declaration
    public override Selectable FindSelectableOnRight()
    Returns
    Type Description
    Selectable

    The nearest Selectable to the right, or null.

    Overrides
    Selectable.FindSelectableOnRight()
    Remarks

    Prevents selection if the Scrollbar moves on the Horizontal axis.

    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly to the right the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element to the right the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnRight();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    FindSelectableOnUp()

    The Selectable object above current

    Declaration
    public override Selectable FindSelectableOnUp()
    Returns
    Type Description
    Selectable

    The nearest Selectable above, or null.

    Overrides
    Selectable.FindSelectableOnUp()
    Remarks

    Prevents selection if the Scrollbar moves on the Vertical axis.

    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI; // required when using UI elements in scripts
    
                            public class ExampleClass : MonoBehaviour
                            {
                                public Button btnMain;
    
                                // Disables the selectable UI element directly above the Start Button
                                public void IgnoreSelectables()
                                {
                                    //Finds the selectable UI element above the start button and assigns it to a variable of type "Selectable"
                                    Selectable secondButton = startButton.FindSelectableOnUp();
                                    //Disables interaction with the selectable UI element
                                    secondButton.interactable = false;
                                }
                            }
    

    GraphicUpdateComplete()

    Callback sent when this ICanvasElement has completed Graphic rebuild.

    Declaration
    public virtual void GraphicUpdateComplete()

    LayoutComplete()

    Callback sent when this ICanvasElement has completed layout.

    Declaration
    public virtual void LayoutComplete()

    OnBeginDrag(PointerEventData)

    Called by a BaseInputModule before a drag is started.

    Declaration
    public virtual void OnBeginDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the drag.

    OnDisable()

    Called when it becomes disabled. Stops driving RectTransform properties.

    Declaration
    protected override void OnDisable()
    Overrides
    Selectable.OnDisable()

    OnDrag(PointerEventData)

    When dragging is occurring this will be called every time the cursor is moved.

    Declaration
    public virtual void OnDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the drag.

    OnEnable()

    Called when it becomes enabled. Begins driving RectTransform properties and updates visuals.

    Declaration
    protected override void OnEnable()
    Overrides
    Selectable.OnEnable()

    OnInitializePotentialDrag(PointerEventData)

    Called by a BaseInputModule when a drag has been found but before it is valid to begin the drag.

    Declaration
    public virtual void OnInitializePotentialDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the drag.

    OnMove(AxisEventData)

    Determine in which of the 4 move directions the next selectable object should be found.

    Declaration
    public override void OnMove(AxisEventData eventData)
    Parameters
    Type Name Description
    AxisEventData eventData

    The axis event data containing the move direction.

    Overrides
    Selectable.OnMove(AxisEventData)
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI;
                            using UnityEngine.EventSystems;// Required when using Event data.
    
                            public class ExampleClass : MonoBehaviour, IMoveHandler
                            {
                                //When the focus moves to another selectable object, Invoke this Method.
                                public void OnMove(AxisEventData eventData)
                                {
                                    //Assigns the move direction and the raw input vector representing the direction from the event data.
                                    MoveDirection moveDir = eventData.moveDir;
                                    Vector2 moveVector = eventData.moveVector;
    
                                    //Displays the information in the console
                                    Debug.Log(moveDir + ", " + moveVector);
                                }
                            }
    

    OnPointerDown(PointerEventData)

    Called when the pointer is pressed. Evaluates the current selection state and transitions to the appropriate state.

    Declaration
    public override void OnPointerDown(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the press.

    Overrides
    Selectable.OnPointerDown(PointerEventData)
    Remarks

    Starts a coroutine to scroll toward the pointer position while the pointer is pressed.

    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI;
                            using UnityEngine.EventSystems;// Required when using Event data.
    
                            public class ExampleClass : MonoBehaviour, IPointerDownHandler// required interface when using the OnPointerDown method.
                            {
                                //Do this when the mouse is clicked over the selectable object this script is attached to.
                                public void OnPointerDown(PointerEventData eventData)
                                {
                                    Debug.Log(this.gameObject.name + " Was Clicked.");
                                }
                            }
    

    OnPointerUp(PointerEventData)

    Called when the pointer is released. Evaluates the eventData and transitions to appropriate state.

    Declaration
    public override void OnPointerUp(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData

    The pointer event data for the release.

    Overrides
    Selectable.OnPointerUp(PointerEventData)
    Examples
      using UnityEngine;
                            using System.Collections;
                            using UnityEngine.UI;
                            using UnityEngine.EventSystems;// Required when using Event data.
    
                            public class ExampleClass : MonoBehaviour, IPointerUpHandler, IPointerDownHandler// These are the interfaces the OnPointerUp method requires.
                            {
                                //OnPointerDown is also required to receive OnPointerUp callbacks
                                public void OnPointerDown(PointerEventData eventData)
                                {
                                }
    
                                //Do this when the mouse click on this selectable UI object is released.
                                public void OnPointerUp(PointerEventData eventData)
                                {
                                    Debug.Log("The mouse click was released");
                                }
                            }
    

    OnRectTransformDimensionsChange()

    Called when the RectTransform dimensions change. Updates visuals.

    Declaration
    protected override void OnRectTransformDimensionsChange()
    Overrides
    UIBehaviour.OnRectTransformDimensionsChange()

    OnValidate()

    Declaration
    protected override void OnValidate()
    Overrides
    Selectable.OnValidate()

    Rebuild(CanvasUpdate)

    Called by the canvas update system to rebuild the scrollbar handle.

    Declaration
    public virtual void Rebuild(CanvasUpdate executing)
    Parameters
    Type Name Description
    CanvasUpdate executing

    The current canvas update stage.

    SetDirection(Direction, bool)

    Set the direction of the scrollbar, optionally setting the layout as well.

    Declaration
    public void SetDirection(Scrollbar.Direction direction, bool includeRectLayouts)
    Parameters
    Type Name Description
    Scrollbar.Direction direction

    The direction of the scrollbar.

    bool includeRectLayouts

    Should the layout be flipped together with the direction?

    SetValueWithoutNotify(float)

    Set the value of the scrollbar without invoking onValueChanged callback.

    Declaration
    public virtual void SetValueWithoutNotify(float input)
    Parameters
    Type Name Description
    float input

    The new value for the scrollbar.

    Update()

    Update the rect based on the delayed update visuals. Got around issue of calling sendMessage from onValidate.

    Declaration
    protected virtual void Update()

    Implements

    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IBeginDragHandler
    IDragHandler
    IInitializePotentialDragHandler
    IEventSystemHandler
    ICanvasElement
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)