Pointer Events on UI Toolkit Sliders

Hey,

I was looking for a way to register callbacks on a Slider reacting to Pointer Events:

The problem is the following: If i register a callback for a pointer event in the way shown below, there is areas of the ui where the slider can already be manipulated, but the event wont fire. If I position the mouse right on the bar (#unity-tracker) where the slider “slides on”, this works.

_slider.RegisterCallback<PointerDownEvent>(_ =>
                Debug.Log($"[{GetType()}] slider was touched")
                );

8469206--1125359--unity_forums.png

So I saw that the slider had an item in it called #unity-drag-container and tried registering the callback on it. Unfortunately without any sucess:

_slider.Q<VisualElement>("unity-drag-container").RegisterCallback<PointerDownEvent>(_ =>
                Debug.Log($"[{GetType()}] Drag container was touched")
                );

So my question is, how do I do this properly?

The sliders value is constantly manipulated by code since it is used as a video control bar. So I cannot simply use ValueChanged Events!

2 Likes

I would change “unity-drag- container” to whatever the handles are called

You ever figure this out? I’m running into the same issue. Trying to store an initial value before the slider changes…

Have you ensured to RegisterCallback<T> with TrickleDown.TrickleDown? By default the callbacks are registered for the bubble up phase. Some controls will prevent the propagation of events when bubbling up, so you need to ensure to register a callback during the trickle down phase.