Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Slider does not drag for ExecuteEvents.dragHandler

Discussion in 'Unity UI & TextMesh Pro' started by trappist-1, May 17, 2018.

  1. trappist-1


    Mar 26, 2017
    I think I have read all articles on Google pertaining to making a slider drag when a pointer hovers over it but am unable to make anything work.

    I am using a VRTK UI pointer but no matter what I try, the slider handle just sits there. I see it change colors when it is focused but it never moves.

    This is one of the ways I have tried to do it but I have no idea what is really going on and no documentation seems to explain the ExecuteEvents or their actual usage.

    Code (csharp):
    1. IEnumerator DoWhileDraggingSliderRoutine(VRTK_UIPointerHandPointerReactor sender, Slider slider, float maxDistance=1.0f) {//This CoRoutine is called after a pointer enter event.
    2.     var pointer = ((VRTK_UIPointerHandPointerReactor)sender).pointerEventData;
    3.     yield return null;
    5.     ExecuteEvents.Execute(slider.gameObject, sender.pointerEventData, ExecuteEvents.pointerDownHandler);
    6.     ExecuteEvents.Execute(slider.gameObject, sender.pointerEventData, ExecuteEvents.beginDragHandler);
    8.     while (sender.hoveringElement == slider.gameObject && sender.pointerEventData.pointerCurrentRaycast.distance < maxDistance) {
    9.         ExecuteEvents.Execute(slider.gameObject, sender.pointerEventData, ExecuteEvents.dragHandler);
    10.         yield return null;
    11.     }
    13.     ExecuteEvents.Execute(slider.gameObject, sender.pointerEventData, ExecuteEvents.endDragHandler);
    14.     ExecuteEvents.Execute(slider.gameObject, sender.pointerEventData, ExecuteEvents.pointerUpHandler);
    15. }
    I get no errors or warnings. Also I have debugged the "While" loop and it does loop and the raycast's worldPosition shows the correct hit position, so the raycasting looks ok...

    I'm completely stumped, still tryin though.


    Either I am doing this completely wrong or VRTK pointer or the UI system is broken. I have tried so many things and none of which ever work.

    I thought this would be trivial, but now I'm clueless as to how to raycast to the UI and click or drag or whatever...

    So I was curious and tried to see if the slider could even handle the event I was sending it.
    I printed the results of CanHandleEvent and the result was True:
    Code (csharp):
    1. print(ExecuteEvents.CanHandleEvent<IDragHandler>(slider.gameObject));
    2. //Prints: True
    So I'm still completely confused as to why it won't move.
    Last edited: May 19, 2018
  2. trappist-1


    Mar 26, 2017
    Finally figured it out!
    And all I had to set was the pointerPressRaycast parameter:
    Code (csharp):
    1. IEnumerator DoWhileDraggingSliderRoutine(VRTK_UIPointer sender, Slider slider) {
    2.     var pointer = sender.pointerEventData;
    3.     pointer.pointerPressRaycast = pointer.pointerCurrentRaycast; //THIS IS CRITICAL!
    5.     while (sender.hoveringElement == slider.gameObject) {
    6.         ExecuteEvents.Execute<IDragHandler>(slider.gameObject, pointer, ExecuteEvents.dragHandler);
    7.         yield return null;
    8.     }
    9.     ...
    Couldn't find any mention of this on any search engine, but I finally stumbled across it in some backyard example somewhere.
    Last edited: May 20, 2018 at 12:07 AM