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

Resolved VR UI Slider Issues

Discussion in 'XR Interaction Toolkit and Input' started by killer1171090, Dec 21, 2020.

  1. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    Hello! Using the Unity XR Plugin for Oculus Quest.
    Everything works great, Except for Slider UI.
    Theres nothing in the way of the Slider, no ui ontop of it, or objects in the way, and it does highlight when i hover over it. But when i click to drag the slider, nothing happens. However sometimes it does move, but it snaps to the start or end of the slider i can never get it in the middle.Other UI works like Dropdowns, Buttons and so on.
    Just Sliders.

    Any ideas?
     
  2. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    75
    Yup, same problem here. It appears to be a fairly recent bug, since I've seen videos of people using sliders with the XR Interaction Toolkit before.

    You can click on the bar part, but if you click on the thumb part you can't drag it.

    I'll file a bug report on it.
     
    killer1171090 likes this.
  3. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    Thanks! For me even the bar part is Highly unreliable, 90% of the time it does nothing, and when it does do something it snaps to either the end or start.
     
  4. mfuad

    mfuad

    Unity Technologies

    Joined:
    Jun 12, 2018
    Posts:
    334
    Hi @BernieRoehl, can you share the case # so I can make sure it's in our queue? Thanks!
     
  5. veenuarora

    veenuarora

    Joined:
    Dec 3, 2020
    Posts:
    1
    Can someone help, how to make ui sliders work for htc vive. I am using steamvr 2.0.
    With laser pointer nothing happens. Will be a great help if someone can give some inputs.
     
  6. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796
    So, Vive support is actually directly handled by HTC. Please share this on their developer forums and their teams will help.
     
  7. OddViz

    OddViz

    Joined:
    Dec 17, 2019
    Posts:
    9
    Chiming in with the same issue. Using the latest XR Interaction Toolkit 1.0.0-pre.4 and Oculus XR Plugin 1.9.1 / OpenXR Plugin 1.1.1. Neither sliders nor scroll rects work properly.
     
  8. roblms

    roblms

    Joined:
    May 28, 2018
    Posts:
    2
    Same slider issue here too. Any updates on a fix?
     
  9. killer1171090

    killer1171090

    Joined:
    Feb 23, 2013
    Posts:
    145
    Never managed to fix it, just worked around it for my game, not using sliders.
     
  10. Deleted User

    Deleted User

    Guest

    I confirm the problem. Also, the buttons sometimes refuse to work.
     
  11. Deleted User

    Deleted User

    Guest

    This means the buttons that are located in the ScrollView.
     
  12. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    If you are using the `XRUIInputModule` you may need to crank up the `Tracked Device Drag Threshold Multiplier`
    By default, the UI system considers something a drag and not a tap when it moves 10 pixels in UI space for 2D input (mouse & touch), and 20 pixels for tracked controllers. Since UI can be far away, and controller input can be jittery, it feels like a much tighter threshold for tracked devices than for 2D. Once it's a drag and not a tap, I suspect the scroll view is taking ownership of the event and consuming it.

    The Event System has a Drag Threshold value that sets the initial 2D value, and then for tracked devices it's multiplied by the Tracked Device Drag Threshold Multiplier. Cranking that number up is a compromise though, you'll get more reliable clicks, but you may not get as responsive drags, so you may need to find a personal sweet spot that fits your game design or rig setup.

    Could also be something else, but I feel like this is at least a thread to pull on.
     
    Deleted User likes this.
  13. Deleted User

    Deleted User

    Guest

    Thanks! this gave the result
     
  14. Leoss

    Leoss

    Joined:
    Apr 18, 2013
    Posts:
    9
    I confirm that the UI slider doesn't work at all when I "Play" inside the Unity editor.
    However when I export either for PC, then it works just fine. So it must be a bug within the Unity editor.

    (Also, changing `Tracked Device Drag Threshold Multiplier` as proposed earlier does nothing to solve the UI Slider issue).
    When can we expect it to be fixed?
     
  15. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    @Leoss
    You are right, I was only responding to the person above, and not the main reported issue in this thread.

    As for sliders, I started looking at it today, and I know why it behaves that way, but I don't know if I have a fast fix for you at the moment.

    TL;DR: It's always been a bug, but there are some situations where it works correctly (UI backing such that the pointer doesn't fade off to infinity between UI elements), so you may have seen it working well in other demos. Please file a bug and ideally attach this thread/info in case it's not me that ends up looking at it.

    The reason sliders don't behave as well in VR has to do with where pointers start from vs. screen-based input. Mouse and Touch input always originates at the screen, and so when you raycast into the world, the position on the screen is the same 1m, 5m, 100m away from the origin. The slider knows where in screen-space, the cursor is so it can figure out how far along the slider is. E.g. in this first image, it's really easy to figure out where the scroll cursor should be even though it's not on the actual slider:
    upload_2021-7-5_11-24-15.png

    For VR, it's different. The origin of the pointer is totally separated from the view. This means that the screen-space location of the cursor is dependent on how far along the ray we are checking. For example in this image, where the red line is the pointer ray: upload_2021-7-5_11-48-50.png

    The screen space position of the pointer could be anywhere along that red line, depending on how deep in the world you want to check. That's just not the case with mouse and touch.

    Normally, in VR, I solved needing screen space in UI events by finding the hit point of the XR pointer and getting it's screen space. This is backwards from mouse and touch where we have the screen space position and use that to find the world space hit point. This means the slider will work well so long as there is some other UI object being hit on the same plane as the slider itself, keeping a consistent depth and therefore screen space position. But when you hit gaps that pass through to infinity or other long distance UI, it starts to misbehave.

    I don't have an immediate fix for this, sadly. The XR UI system was setup to try to integrate as seamlessly with the existing UI as possible so we didn't need XR Slider, XR Dropdown, etc..., but in this situation, I may need to modify the slider to find a good way to adjust how screen space is determined for pointers, though I think this second option would break UI elsewhere.
     
    Last edited: Jul 5, 2021
    Pawciu and jason-vreps like this.
  16. jason-vreps

    jason-vreps

    Joined:
    Sep 22, 2017
    Posts:
    16
    Thank you for this insightful reply @StayTalm_Unity. We have a similar situation and your explanation has helped clarify some aspects of it.

    In our VR app, our main UI exists all together on a single panel. This panel is buried deep underground, out of the way, and a render texture displays this UI on several "TV screens" scattered about our play space. We detect interactions with the TV screen, and put a second XR Ray Interactor on our (underground) UI at the exact same place. Sounds hacky, but it works great! Only issues so far are:

    1. Multiple XR Ray Interactors don't reliably send button actions on clicks
    2. Scrollviews and Slider bars have unreliable characteristics

    Item 2. is exactly the scenarios we're discussing here. I've noticed that if I select+hold a slider or scrollview, and move my head left/right, the slider/scrollview will move about as well! This is highly exacerbated by having a UI several 100m's underground, which I now understand much more clearly, tyvm.

    Even though it's undesirable, in order to ship reliable VR UI to our customers, do you have a quick recommendation for building and interim XR Slider and XR Scrollview? I love where the XR kit is going, and think it's absolutely the right idea. But explaining the complications of these problems doesn't satisfy customers who just want functioning VR UI :D
     
  17. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    100% with you. Theory is nice, but even if we have bugs, you've still got to ship.

    So, I attached an XR Slider. Mostly copy-paste, hacking out some Internal calls, and modifying a single function.

    That function is UpdateDrag:

    Code (CSharp):
    1.         void UpdateDrag(PointerEventData eventData, Camera cam)
    2.         {
    3.             RectTransform clickRect = m_HandleContainerRect ?? m_FillContainerRect;
    4.             if (clickRect != null && clickRect.rect.size[(int)axis] > 0)
    5.             {
    6.                 Vector2 position = Vector2.zero;
    7.                 if (eventData is TrackedDeviceEventData trackedDeviceEventData)
    8.                 {
    9.                     clickRect.GetWorldCorners(s_Corners);
    10.                     var plane = new Plane(s_Corners[0], s_Corners[1], s_Corners[2]);
    11.                    
    12.                     var rayPoints = trackedDeviceEventData.rayPoints;
    13.                     for (var i = 1; i < rayPoints.Count; i++)
    14.                     {
    15.                         var from = rayPoints[i - 1];
    16.                         var to = rayPoints[i];
    17.                        
    18.                         var rayDistance = Vector3.Distance(to, from);
    19.                         var ray = new Ray(from, (to - from));
    20.                        
    21.                         if(plane.Raycast(ray, out var distance))
    22.                         {
    23.                             if (distance < rayDistance)
    24.                             {
    25.                                 var worldPoint = ray.origin + (ray.direction * distance);
    26.                                 position = cam.WorldToScreenPoint(worldPoint);
    27.                                
    28.                                 Debug.DrawLine(from, worldPoint);
    29.                                 break;
    30.                             }
    31.                         }
    32.                     }
    33.                 }
    34.                 else
    35.                 {
    36.                     position = eventData.position;
    37.                 }
    38.                
    39.                 Vector2 localCursor;
    40.                 if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, position, cam, out localCursor))
    41.                     return;
    42.                 localCursor -= clickRect.rect.position;
    43.  
    44.                 float val = Mathf.Clamp01((localCursor - m_Offset)[(int)axis] / clickRect.rect.size[(int)axis]);
    45.                 normalizedValue = (reverseValue ? 1f - val : val);
    46.             }
    47.         }
    I cut out multi-monitor support (used Internal calls), and everything inside of `if (eventData is TrackedDeviceEventData trackedDeviceEventData)` is custom. What I do is create create a plane struct that represents the slider button, and then figure out where the pointer ray intersects that virtual plane. I use that to determine my screen position, and then fall through all the same logic as the normal slider. The scrolling area should be very similar, do a search for eventData.position, and replace that value with the raycast against plane code above.

    However, this only fixes half the issue. The positioning is now correct, but it doesn't have the same behaviour as a mouse where it still calculates the position of the scroller even if I'm not pointing at anything. It just sort of stops whenever I point into open space.
    I traced this down to the UIInputModule. There is some code in the `internal void ProcessTrackedDevice(ref TrackedDeviceModel deviceState, bool force = false)` that is broken on drag. If you look at this blob:
    Code (CSharp):
    1.                 Vector2 screenPosition;
    2.                 if (eventData.pointerCurrentRaycast.isValid)
    3.                 {
    4.                     screenPosition = camera.WorldToScreenPoint(eventData.pointerCurrentRaycast.worldPosition);
    5.                 }
    6.                 else
    7.                 {
    8.                     var endPosition = eventData.rayPoints.Count > 0 ? eventData.rayPoints[eventData.rayPoints.Count - 1] : Vector3.zero;
    9.                     screenPosition = camera.WorldToScreenPoint(endPosition);
    10.                     eventData.position = screenPosition; // <------- This line right here needs to be deleted
    11.                 }
    12.  
    13.                 var thisFrameDelta = screenPosition - eventData.position;
    14.                 eventData.position = screenPosition;
    15.                 eventData.delta = thisFrameDelta;
    I put a comment on the line that needs to be removed. It's shorting out the calculation of eventData.delta directly below it. This brings back the ability to update drag while pointing at nothing. This one is a little awkward for you to patch in as you'll also need to bring in a custom XRUIInputModule and I believe a lot of XRI is internal. You may be able to clone the package and put it locally in your packages folder if you just want to make custom modifications directly.

    Please report both these as bugs. I know these systems, and want to help, but I'm working on other things, and doubtful I'll be the one tackling these issues directly.

    Hope this helps!
     

    Attached Files:

    jason-vreps likes this.
  18. jason-vreps

    jason-vreps

    Joined:
    Sep 22, 2017
    Posts:
    16
    Big thanks @StayTalm_Unity. I had spoken with some customers who were aware of this situation and they are quite happy with the fix. I meant to circle back a while ago, but better late. Thanks so much!
     
  19. MeepyManX

    MeepyManX

    Joined:
    Aug 16, 2012
    Posts:
    2
    After reading all of this thread I noticed I forgot to add the correct Event camera on the Canvas that the UI Slider was attached to. I had it set to a disabled camera on accident.
     
    ltomov likes this.
  20. andykibz

    andykibz

    Joined:
    May 19, 2020
    Posts:
    1
    I've also encountered the same problem while working with Sliders but I think I've found a quick fix but before that let me give some context...First, if I understood @StayTalm_Unity I think that's the issue(IMO not that I am experienced). If you are like me, then you usually create a canvas in WorldSpace, set the Width and Length on the RectTransform component of the canvas, then when you add a slider to it, you scale it down instead of working with other RectTransform parameters.
    So my fixes:
    1. At the start, you could just scale your canvas instead of setting its width and height. I noticed this is how Valem did it in his Introduction to VR in Unity series Part 6. But if you have progressed far beyond this point...
    2. Create another World Space canvas and configure it as you so please(or based on the previous one) and most importantly leave the width and height as is but change the scale. Then copy the slider GameObject from the old Canvas to the new while maintaining its right location in WorldSpace. You can disable or delete the old slider if you so wish. The 2 canvases do not have to be in the same location though.
    I've implemented option 2 and it seems to work for me so far. Hope someone else finds this useful before a better fix is provided.
     
    Banosa likes this.
  21. RogueStargun

    RogueStargun

    Joined:
    Aug 5, 2018
    Posts:
    286
    Is this still broken? If so, it does appear to be aggravating my goal of adding volume, music, and graphics sliders to my game.
     
  22. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    254
    Hey @RogueStargun,

    This is still an issue when the pointer is not hitting a UI element (firing off to infinity). There are a couple of workarounds that will work until a proper fix is released.

    Option 1: Create a Hit Background (Image) child object on the Slider and scale that to accommodate some buffer. You could stylize this image or make it transparent if you want the 'floating slider' effect.

    Option 2: The default Background child object has Raycast Padding in the Image component that can be adjusted to achieve the same effect as option 1. I had to crank these to about 200 left/right and 50 top/bottom to get it feeling good, but it will depend the size of your slider and the scale of your UI elements.

    Both of these have the added benefit of reacting to clicks near the slider bar when parented to an existing panel or not (floating), which really helps lower user frustration.

    Let us know if these are workable solutions for you.
     
    Last edited: Jan 26, 2022
  23. KineticBen

    KineticBen

    Joined:
    Jul 19, 2021
    Posts:
    10
    I'm a getting this issue still too in v2.0.1. If it helps, this is also happening with scroll rects too.
     
  24. tlskillman

    tlskillman

    Joined:
    Dec 12, 2015
    Posts:
    16
    Still not working. Can click a point on slide and handle will jump there, but can't drag the handle to a point. Basically a useless slider.
     
  25. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    254
    Hey all,
    We did find a minor issue with dragging Sliders and ScrollRects in our XRUIInputModule that will be fixed in the upcoming version (2.0.2). We saw a similar complaint and partial fix in another thread which led us to investigate. Historically, there was a bug fix in the InputSystem version that didn't get applied to the XRI one. Thanks again @AzurySimon for calling this out.
     
    AzurySimon likes this.
  26. jimmychen0123

    jimmychen0123

    Joined:
    May 17, 2020
    Posts:
    12
    The UI slider is still not draggable in the XR tool kit version 2.1.1
     
    dweeh likes this.
  27. NuShrike

    NuShrike

    Joined:
    Aug 5, 2021
    Posts:
    2
    Replicated still broken in Unity 2021.3.11f1 with XRI Toolkit version 2.1.1 . World-space Canvas camera is set.

    The XRSlider component replacement from @StayTalm_Unity still works. Just be sure to fill in after replacing the stock Slider component:
    * Target Graphic
    * Fill Rect
    * Handle Rect
     
    Last edited: Oct 18, 2022
  28. Dknighter2

    Dknighter2

    Joined:
    Aug 17, 2014
    Posts:
    44
    Hey, we are having this problem with Phasmophobia with all sliders and scroll rects. It is a major problem for our VR players. We are using Unity 2021.3.11f1, XR Toolkit version 2.2.0 and OpenXR 1.5.3.

    The fix above for sliders works great and we will be swapping our sliders to that however scroll rects still won't work.

    We would be really grateful if you can fix this as soon as possible.