Drag a Slider while having pointer down on another object

I have a hidden slider object. When you press and hold on an image the slider appears righter above the image, when you let go the slider disappears.

I want to trigger the drage event of the slider handle automatically so you can move the slider while holding down on the image. I’ve tried a lot with Execute Events but the only thing that had any effect was ExecuteEvents.Execute(slider, e, ExecuteEvents.pointerDownHandler); which only selected the slider knob but didn’t move it.

I tried various combinations of ExectureEvents.beginDragHandler/initializePotentialDrag/dragHandler/movHandler but to no avail and I’m just guessing anyway so I hope you can help.

 public void OnDrag()
    {
        slider.SetActive(true);
        e = new PointerEventData(EventSystem.current);
      

        ExecuteEvents.Execute(slider, e, ExecuteEvents.initializePotentialDrag);
        ExecuteEvents.Execute(slider, e, ExecuteEvents.beginDragHandler);

}

Rather than trying to create a fake drag event on your slider, I would suggest you convert the real drag event (on your image) into a numerical value, and then simply set your slider’s value through script.

Depending on the details of how you want this to work, you might even want that visible image to be a (second) slider.

1 Like

Oh, I didn’t even think about that! :smile: Works fine, thanks. :slight_smile: