ViveSoftware / ViveInputUtility-Unity

A toolkit that helps developing/prototyping VR apps.
http://u3d.as/uF7
Other
357 stars 81 forks source link

Sometimes canvas elements aren't interactable (sorted by distance) #94

Open frg-kova opened 5 years ago

frg-kova commented 5 years ago

Bug: sometimes pointers on canvas can't interact with buttons VIU 1.10.3

Steps to reproduce: Create a popup menu with some buttons and a background image that blocks raycasts. Spread the buttons all over. Create the menu in front of the player in play space area and try to see if all buttons can be interacted with.

Cause: PointerInput3DModule.RaycastComparer() first sorts the canvas elements by distance first, while it should be by depth. Due to RectTransform and how they work, a button on the canvas can be a tiny bit farther away then the panel behind it, causing the panel to be the target hit instead of a button.

After sorting by depth first, I didn't see the problem, but I don't know if something else needs distance before depth. Ideally we would detect if element is on same canvas, then ignore distance?

See Pointer3dInputModule.RaycastComparer(), line ~187

chengnay commented 5 years ago

@frg-kova Can you provide the project that you created? I just tried like the way you describe above, but I could not reproduce the issue. Did you add Canvas Raycast Target to your popup menu?

My project looks something like this, and it works fine. image image

frg-kova commented 5 years ago

Jos to reiterate, raycasting on canvas works, it's just that button and panel behind it are wrongly sorted (by distance, which should be the equal). I tried but can't reproduce in new project. I can reproduce it in my extremely big project that I can't send. It's a popup menu with 2 buttons that appears in front of the camera and faces the camera. About every 5th time it's spawned, it has the bug. Sometimes both buttons don't work, sometimes just one button. I've tracked the bug to distance comparison to camera vs panel behind it, they differ a tiny little bit, like 0.000x. Don't really have the time to hunt id down now, maybe I'll post an update later, for now I hope I helped out if somebody encounters the same bug.

chengnay commented 5 years ago

@frg-kova You mentioned "It's a popup menu with 2 buttons that appears in front of the camera and faces the camera.", do you mean your popup menu will move with camera or it stays stationary? And, "About every 5th time it's spawned, it has the bug.", do you mean that you close and open for the 5th time? I am not really sure why this issue doesn't reproduce in the new project. If cannot reproduce in new project, I am not able to track down this bug and fix it in my side. If you have any more clue about this issue, please let us know, thanks!

frg-kova commented 5 years ago

It's spawns in play area space, in front of camera, facing the camera. I spawn it every time I press the menu button. I know the bug is now in limbo state, maybe I'll strip down the big project to just play area and the menu when I get the time.

lupustom commented 5 years ago

We are experiencing the same issue. Changing the order of comparisons to depth before distance did also work for us, however the fix does not seem to be satisfactory.

We can also reproduce the bug in a clean scene with just a canvas, a background image and a button, if the canvas is placed at a certain position and the button is placed at a certain position within the canvas. Although all canvas elements' z positions are set exactly to 0, the distance returned in the Raycast Result is slightly different (similar to what @frg-kova reported). The funny thing is, as one moves away from the canvas, the difference in distance gets smaller and at some point disappears and everything works fine.

Canvas Button Other button

chengnay commented 5 years ago

@lupustom I tried the values you have above, but I couldn't reproduce. Could you provide a sample project and also a video to show your findings? Thanks!

lupustom commented 5 years ago

@chengnay Apologies for the late reply. Just wanted to attach a zip of the sample project, but it's 26MB and GitHub only lets you upload 10MB max ... is there another way to get it to you?