Infinite loop UI Button OnClick() event when selecting a file/folder when using XR Interaction Toolkit
yaelmartin opened this issue · 0 comments
Unity version : 2021.3.17f1
When using the default "Complete XR Origin Setup" in the XR Interaction Toolkit (tested with 2.3.0 pre-1, and 2.3.0) package,
UI Buttons will trigger their OnClick() event twice/infinitely when calling a StandaloneFileBrowser.OpenFilePanel(); somewhere AND a file is selected.
-StandaloneFileBrowser.OpenFilePanel() isn't asynchronous. While using a synchronous function in VR isn't a great idea, maybe my fix could help someone in the future.
(Each time I wrote "Clicking a UI Button" means a button calling the function StandaloneFileBrowser.OpenFilePanel(); )
Clicking a UI Button located in canvas World Space with the VR controllers:
-If a file/folder is selected in the first pop up explorer using the desktop mouse without pausing VR (ex: opening SteamVR dashboard), high chance of the button and pop up explorer being called another time.
-If a file/folder is selected in the first pop up explorer while the SteamVR dashboard is opened, there is less chance of the button and pop up explorer being called another time.
Clicking a UI Button located in a canvas Screen Space Overlay from the desktop Unity window and a mouse:
-If a file/folder is selected in the first pop up explorer, the button WILL be called another time and a new pop up explorer will appear.
Fix I found that doesn't seem to break the XR experience:
-Disable the EventSystem component or entire gameobject inside the "Complete XR Origin Setup".
-Attach a new EventSystem component to an active gameobject in the scene (a new XRUIInputModule component will automatically attach)
Note: calling the same function wich calls the StandaloneFileBrowser.OpenFilePanel() in a XRGrabInteractible Activate() Event will work without opening a second pop up explorer window.
I have now found that by using the reproduce steps below, the window will continue to appear as long as you select a file!
The dekstop Canvas issue is always present. The bug seems to be more prone to happen on a VR WorldSpace canvas the more demanding the scene is. Action event on a XRGrabInteractable won't ever fire twice.
To reproduce :
Import and load the XR Interaction Toolkit DemoScene.unity in Assets\Samples\XR Interaction Toolkit\2.3.0-pre.1\Starter Assets
Import UnitySandaloneFileBrowser
Create a new cube and attach the provided DebugCube.cs script (DebugCube.cs)
Make a ScreenSpace UI canvas with a button (for the desktop view)
Make the button call the Click() function of the DebugCube
Enter play mode
Click on the Button. If you select an item in the window, another explorer window will appear, the int numberOfClicks in the DebugCube will increase. This is looping.
Now try my fix. The button OnClick() event should now be only called once.