MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Unreliable/Confusing Button Touch Behaviour

Open atiemark opened this issue 5 years ago • 11 comments

Describe the bug

This issue turned up in a project during the development phase. Buttons worked in this project before. Unfortunately it was not possible to trace back the cause.

Touch registers very unreliably with the Standard Hololens2 Button from the MRTK Toolbox. The only property that was modified is the Transform of the GameObject, GameObject Name, Text and Icon.

A copy of the StartAdjustingGeometryButton GameObject as a child of Menus/MainMenu (left button in the Video) has the exact same settings displayed in the Inspector as the tested button but is even more unreliable.

Please see this video from my HL2 App for a demonstration:

https://user-images.githubusercontent.com/33260631/113730570-4ba39680-96f8-11eb-91fe-5d51ce9531fc.mp4

Watching the video with sound makes it easier to notice when touch has been registered and when not.

See the Screenshot for the tested Button in the Inspector.

Expected behavior

The button should register a touch input reliably every time.

Screenshots

HiarachyAndSettings

Your setup (please complete the following information)

  • Unity Version 2019.4.20f1
  • MRTK Version 2.6.1

Target platform (please complete the following information)

  • HoloLens 2

atiemark avatar Apr 06 '21 14:04 atiemark

Still haven't managed to solve this issue or any idea where it comes from - trying to isolate it by trial and error.

atiemark avatar Apr 13 '21 13:04 atiemark

Can you replicate this in with input simulation? Generally wondering if there's a consistent way to repro this.

RogPodge avatar Apr 14 '21 22:04 RogPodge

Steps to reproduce this issue - a minimal, reproducible example:

  • Create 2 Canvas Gameobjects with 1 MRTK Button as a child GameObject for each.

  • Follow the How-to on Pressable Buttons (Convert to MRTK Canvas, scale the canvas, add NearInteractionTouchableUnityUI) https://docs.microsoft.com/de-at/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/button#how-to-use-pressable-buttons

  • Deploy to HL2.

In my tests, one button then had this issue.

I am wondering if the Buttons from the MRTK Toolkit are supposed to or can be used without a (MRTK) Canvas as a parent? Trying to build a Scene with several Menus and therefore Canvases. When only one Canvas is active (while there are several in the scene), there is no issue.

This seems like a render collision scanning / render order problem?

What is the appropriate/suggested way to build a multi-menu scene? One canvas, buttons without canvas or multiple canvases ?(the latter is possible and even recommended with the default Unity UI elements, see "Divide up your canvases": https://unity3d.com/how-to/unity-ui-optimization-tips)

atiemark avatar Apr 18 '21 20:04 atiemark

@CDiaz-MS @cre8ivepark you might be more familiar with the latter question, since you've both done practical implementations of UI canvas's recently

@atiemark We'll track this issue and hopefully get back to you with a repro + solution

RogPodge avatar Apr 19 '21 19:04 RogPodge

@atiemark I just ran into something similar and I suspect this may be related to the Scale property of the buttons. Try changing Scale from 1.5 to 1, or increase the size of the Box Collider and NearInteractionTouchable Bounds properties by 50%.

justinpando avatar Apr 20 '21 20:04 justinpando

@atiemark I just ran into something similar and I suspect this may be related to the Scale property of the buttons. Try changing Scale from 1.5 to 1, or increase the size of the Box Collider and NearInteractionTouchable Bounds properties by 50%.

According to my minimal reproducible example this also occurs with out of the box sized buttons when using 2 canvases, see above: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/9624#issuecomment-822051709

atiemark avatar Apr 21 '21 10:04 atiemark

Quick update on this, was able to repro, and taking a deeper dive in what's causing the unpress behavior

RogPodge avatar Apr 27 '21 23:04 RogPodge

Ok I've root caused the issue.

This occurs when the button is pressed in the space where two canvas's are overlapping. Evidence below

touchableUI

The reason for this is in these two sections:

https://github.com/microsoft/MixedRealityToolkit-Unity/blob/08587f724bf9f2d067189639c3a415649566ba8e/Assets/MRTK/SDK/Features/UX/Scripts/Pointers/PokePointer.cs#L154-L161

and

https://github.com/microsoft/MixedRealityToolkit-Unity/blob/08587f724bf9f2d067189639c3a415649566ba8e/Assets/MRTK/SDK/Features/UX/Scripts/Pointers/PokePointer.cs#L175-L182

Basically, when two canvas's are overlapping, the newClosestTouchable variable will get set to the canvas that was last created, since both canvas's are considered equidistant from the pointer (this makes sense, since distance is measured as the shortest path to the canvas's surface, and the two overlap on the same plane)

This problem can be solved by making sure the canvas's are never overlapping, whether that be through positioning or by changing their width and height to 0. Part of me thinks that this piece of the instructions

Set the Rect Transform component's X, Y, and Z scale to 0.001

is meant to stop this canvas overlapping behavior, but I'm not entirely sure

@cre8ivepark I see you were an author on that document can you confirm that assessment?

RogPodge avatar Apr 28 '21 06:04 RogPodge

@RogPodge I'm not familiar with the technical details since I mostly did example layout & visual polish. I remember that UGUI examples with NearInteractionTouchableUnityUI were added by Adam(MRW) PR - https://github.com/microsoft/MixedRealityToolkit-Unity/pull/5781

cre8ivepark avatar May 01 '21 05:05 cre8ivepark

Looking at how Unity, it looks like they are able to handle buttons on overlapping canvas's just fine, meaning our canvas differs form Unity's native canvas in behavior. For now, going to update the documentation to inform users to avoid the pitfall of having overlapping canvases, as it would take some effort to identify and implement the right way to fix this.

RogPodge avatar May 03 '21 20:05 RogPodge

Docs have been updated, closing this PR

RogPodge avatar May 04 '21 22:05 RogPodge