Unreliable/Confusing Button Touch Behaviour
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
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
Still haven't managed to solve this issue or any idea where it comes from - trying to isolate it by trial and error.
Can you replicate this in with input simulation? Generally wondering if there's a consistent way to repro this.
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)
@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
@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%.
@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
Quick update on this, was able to repro, and taking a deeper dive in what's causing the unpress behavior
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

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 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
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.
Docs have been updated, closing this PR