Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Events to notify when a slider is dragging

Discussion in 'UI Toolkit' started by Aaron-Meyers, Jan 21, 2023.

  1. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    I need to know the state of a slider, when it begins dragging and when it stops dragging. Are there events for that? I tried using DragEnterEvent and DragLeaveEvent with RegisterCallback, but I never got anything. What's the correct way?
     
  2. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    230
    Sliders internally use MouseEvents/PointerEvents to detect drag, you could register to these pointer down/pointer up events on TrickleDown, on the drag element (className: Slider.draggerUssClassName).
     
  3. LarsLundh

    LarsLundh

    Joined:
    Sep 6, 2022
    Posts:
    20
    Anyone else visiting here in the future.

    This worked for me:

    Code (CSharp):
    1. Slider.RegisterCallback<MouseCaptureOutEvent>(OnScrubberSliderReleased);
    2. // dont forget to unregister in the detachFromPanelEvent handler
    3. Slider.UnregisterCallback<MouseCaptureOutEvent>(OnScrubberSliderReleased);
     
    Last edited: Jul 18, 2023
    gzeeebra and DMGrizz like this.