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

Input on Unity UI not working ONLY when ran with WMR

Open slavabielkin opened this issue 7 years ago • 18 comments

Describe the bug

Reopening the issue: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/4305

Unity UI input does not work in app built for WMR (both controllers and gaze input can not even highlight any interactable item). The same app built for Hololens works fine. Physics raycast and input works fine on both configurations.

The UI raycast does stop on the Canvas, but the button did not highlight on hovering and click did nothing. Also, simulating the controllers in the WMR Portal while running the Unity Editor worked.

To reproduce

Create a new Unity Project Add only the MRTK2 with Examples Build a project with the scene HandInteractionUnityUIExample.unity

Expected behavior

When hovering or clicking a Unity UI button, the button should react accordingly.

Setup

Unity: 2018.3.14f1, 2019.1.0f2 Mixed Reality Toolkit 2.0.0-RC1-Refresh OS version: 10.0.17763 Build 17763 Mixed Reality Portal Version: 2000.19011.1132.0 (I tried to re-install it too).

slavabielkin avatar Jun 10 '19 21:06 slavabielkin

This issue has been marked as stale by an automated process because it has not had any recent activity. It will be automatically closed in 30 days if no further activity occurs. If this is still an issue please add a new comment with more recent details and repro steps.

stale[bot] avatar Feb 20 '20 02:02 stale[bot]

More Information

Adding a note to this issue, I am receiving this issue as well. But intermittently.

Unity UI works fine with the Unity editor.

Steps to reproduce

  • Build a scene that includes a Unity UI
  • When running in the build, test that the Unity UI works.
  • If the Unity UI works, restart your machine as many times as required until it doesn't

Additional notes

  • I have had this issue intermittently for the past few months.

  • I have made a build on Computer A, tested the Unity UI.. It works. I performed a restart on the request of my manager and then the Unity UI stopped working. The same build was run on another machine, and the Unity UI worked.

DanCRichards avatar Mar 02 '20 02:03 DanCRichards

Information regarding the restarting of the computer comes from another issue that discusses the same issue and how restarting the computer multiple times seems to fix the issue.

Other issues with similar descriptions talk about scene changes, which is what occurs in our project, although when Unity UI doesn't work, it doesn't work on the original 'Lobby' scene either.

DanCRichards avatar Mar 02 '20 02:03 DanCRichards

Any update on this? I am facing this issue on version 2.4 as well. This is a huge blocker for me as my project entirely uses unity UI

albinhw avatar Jul 06 '20 03:07 albinhw

@StephenHodgson @davidkline-ms

albinhw avatar Jul 12 '20 21:07 albinhw

Doesn't surprise me it's not addressed/fixed yet.

Likely there's a missing event not being raised somewhere or the wrong input module is being added to the camera rig.

Probably best to use UI elements or a completely 3d GUI.

Please don't @ me again for mrtk related issues.

StephenHodgson avatar Jul 12 '20 21:07 StephenHodgson

I have a stupid and very bad workaround: when it appens, you have to move and click the mouse. Really. When the input doesn't interact with the UI, with the input switching settled for VR, move and click your mouse for less than a second, and will works (doesn't work with emulated input, in that case you have to disable mouse input virtualization, move and click with mouse and re-enable mouse input virtualization). We have added this trick inside the page of our app in Microsoft store.....really. IMG_20200713_004316

pocce90 avatar Jul 12 '20 22:07 pocce90

@pocce90 Thank you for the workaround! I am facing this issue with unity UI and it is so random. The UI arbitrarily stops working. Let me try out this workaround

ajnaduvil avatar Jul 13 '20 09:07 ajnaduvil

@pocce90 Thank you for the workaround! I am facing this issue with unity UI and it is so random. The UI arbitrarily stops working. Let me try out this workaround

We also added a code that moves the mouse automatically, and works! but doesn't work if the input is not settled for VR (Win+Y) or if the controllers are virtualized

pocce90 avatar Jul 20 '20 10:07 pocce90

@pocce90 That is great. Is the script part of the MR application? How did you invoke mouse movement from UWP app?

albinhw avatar Jul 20 '20 11:07 albinhw

I don't know if it's great, because it solves only the 30%-40% of cases i think, but it's better than nothing:

[DllImport("User32.dll")]
private static extern bool SetCursorPos(int X, int Y);
    void Start()
    {
        MouseMove();
    }

    async void MouseMove()
    {
        for (int i = 0; i < 5; i++)
        {
            SetCursorPos(i * 100, i * 100);
            await Task.Delay(100);
        }
    }

pocce90 avatar Jul 20 '20 13:07 pocce90

I don't know if it's great, because it solves only the 30%-40% of cases i think, but it's better than nothing:

[DllImport("User32.dll")]
private static extern bool SetCursorPos(int X, int Y);
    void Start()
    {
        MouseMove();
    }

    async void MouseMove()
    {
        for (int i = 0; i < 5; i++)
        {
            SetCursorPos(i * 100, i * 100);
            await Task.Delay(100);
        }
    }

I tried this solution in a WMR build. Getting the following exception "DllNotFoundException: Unable to load DLL 'User32.dll': The specified module could not be found." User32.dll not getting loaded in UWP build

@pocce90 were you able to get it worked on a uwp build?

albinhw avatar Aug 29 '20 06:08 albinhw

We are working on a PR to fix the issue which should come out pretty soon. In the meantime please go to the Main Camera gameobject (under MixedRealityPlayspace) and set Force Module Activation in the MixedRealityInputModule component to true in the inspector. Please let us know if that works for you.

MaxWang-MS avatar Oct 22 '20 05:10 MaxWang-MS

@DanCRichards @albinhw @pocce90 @bielkinv @ajnaduvil The issue has been fixed and please try the mrtk_development branch and let us know if it works for you. Please do not set the Force Module Activation bool and just use its default value (which should be false) when testing the mrtk_development branch.

MaxWang-MS avatar Oct 23 '20 02:10 MaxWang-MS

Hello,

Same issue, but I'm not using the MRTK, simply trying to get on screen UI to work in a WMR build using Unity 2019.4.11f1. Are there specific settings that need to be set under player settings or some functions to call by script to get this to work? Similar to above comments, I have been able to get the UI to work ONCE by moving the mouse around during app launch, but usually the UI will suddenly become unresponsive

ceitel avatar Dec 03 '20 21:12 ceitel

@ceitel Do you have a StandaloneInputModule component attached to the main camera? If so try setting Force Module Activation in that component to true in the inspector. Please let us know if that works for you. Also please considering filing a Unity bug report as the problem occurs without MRTK so that hopefully Unity can get this fixed.

MaxWang-MS avatar Dec 03 '20 22:12 MaxWang-MS

@MaxWang-MS thanks for the quick reply. I'm actually using a script for basic on-screen UI (OnGUI() and GUI.Button() for example), one of these buttons is a "settings" button which then switches from a VRInputModule to the StandaloneInputModule, but the basic OnGUI() elements lose function, these do not require an Event System.

In short, the basic OnGUI() script UI loses functionality as soon as I call a coroutine to:

private IEnumerator LoadWindowsMR()
{
    string devName = "WindowsMR";
    Debug.Log(string.Format("LoadDevice: newDevice {0}, prevDevice {1}", devName, XRSettings.loadedDeviceName));
    XRSettings.LoadDeviceByName(devName);
    yield return null;
    XRSettings.enabled = true;
}

let me know if you have any suggestions, if not I'll file that bug report.

Thanks!

EDIT: If I press the settings button before XR is enabled, it will open my settings panel and switch to the StandaloneInputModule, but as soon as XRSettings.enabled = true I lose both the OnGUI functionality as well as the StandaloneInputModule functionality

ceitel avatar Dec 04 '20 00:12 ceitel

Unfortunately in that case I can only suggest that you file the bug with Unity.

MaxWang-MS avatar Dec 04 '20 05:12 MaxWang-MS