microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Missing UIRaycastCamera error #10583

Closed genereddick closed 9 months ago

genereddick commented 2 years ago

Describe the bug

Removed and recreated the Unity library folder and the app started spewing errors. I don't think anything else changed. Clearing the cache, removing and readding MRTK, made no difference.

Trying to trace this to the source without much success. A new project doesn't have the issue, but a new scene in the existing project with all default Toolkit settings does.

In FocusProvider.cs the Initialize method never gets called and so the Raycast camera never gets set up:

`#region IMixedRealityService Implementation

    /// <inheritdoc />
    public override void Initialize()
    {
        if (!IsSetupValid) { return; }

        base.Initialize();

        if (Application.isPlaying)
        {
            Debug.Assert(uiRaycastCamera == null);
            FindOrCreateUiRaycastCamera();
        }`

Oddly, while it never gets called on startup, it does get called when the application is stopped. The first method, get called but never reaches the FocusProvider initialize, but the second method does when the app is shutting down:

private bool ExecuteOnAllServicesInOrder(Action<IMixedRealityService> execute)

private bool ExecuteOnAllServicesReverseOrder(Action<IMixedRealityService> execute)

And, as a terrible hack, I can force it to initialize by editing the MixedRealityToolkit.cs by adding to the execute(services[i]), getting the focus provider service and calling Initialize on it. But I have no idea how this happened or how to fix it.

`private bool ExecuteOnAllServicesInOrder(Action<IMixedRealityService> execute)
    {
        using (ExecuteOnAllServicesInOrderPerfMarker.Auto())
        {
            if (!HasProfileAndIsInitialized)
            {
                return false;
            }

            var services = MixedRealityServiceRegistry.GetAllServices();
            int length = services.Count;
            for (int i = 0; i < length; i++)
            {
                execute(services[i]);

                if (i == 1)
                {
                    var focusProviderService = services[1] as IMixedRealityFocusProvider;
                    if (focusProviderService.UIRaycastCamera == null)
                    {
                        focusProviderService.Initialize();
                    }
                }
            }

            return true;
        }
    }`

A clear and concise description of what the bug is. Missing UIRaycastCamera! UnityEngine.Debug:Assert (bool,string) Microsoft.MixedReality.Toolkit.Input.FocusProvider:RaycastGraphics (Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointer,UnityEngine.EventSystems.PointerEventData,UnityEngine.LayerMask[],Microsoft.MixedReality.Toolkit.Input.FocusProvider/PointerHitResult) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:1363) Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointer (Microsoft.MixedReality.Toolkit.Input.FocusProvider/PointerData) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:1070) Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointers () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:974) Microsoft.MixedReality.Toolkit.Input.FocusProvider:Update () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:554) Microsoft.MixedReality.Toolkit.MixedRealityToolkit/<>c:b__72_0 (Microsoft.MixedReality.Toolkit.IMixedRealityService) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1054) Microsoft.MixedReality.Toolkit.MixedRealityToolkit:ExecuteOnAllServicesInOrder (System.Action`1) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1145) Microsoft.MixedReality.Toolkit.MixedRealityToolkit:UpdateAllServices () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1054) Microsoft.MixedReality.Toolkit.MixedRealityToolkit:Update () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:727)

NullReferenceException: Object reference not set to an instance of an object Microsoft.MixedReality.Toolkit.Input.FocusProvider.RaycastGraphics (Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointer pointer, UnityEngine.EventSystems.PointerEventData graphicEventData, UnityEngine.LayerMask[] prioritizedLayerMasks, Microsoft.MixedReality.Toolkit.Input.FocusProvider+PointerHitResult hit) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:1364) Microsoft.MixedReality.Toolkit.Input.FocusProvider.UpdatePointer (Microsoft.MixedReality.Toolkit.Input.FocusProvider+PointerData pointerData) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:1070) Microsoft.MixedReality.Toolkit.Input.FocusProvider.UpdatePointers () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:974) Microsoft.MixedReality.Toolkit.Input.FocusProvider.Update () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/FocusProvider.cs:554) Microsoft.MixedReality.Toolkit.MixedRealityToolkit+<>c.b__72_0 (Microsoft.MixedReality.Toolkit.IMixedRealityService service) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1054) Microsoft.MixedReality.Toolkit.MixedRealityToolkit.ExecuteOnAllServicesInOrder (System.Action`1[T] execute) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1145) Microsoft.MixedReality.Toolkit.MixedRealityToolkit.UpdateAllServices () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:1054) Microsoft.MixedReality.Toolkit.MixedRealityToolkit.Update () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Core/Services/MixedRealityToolkit.cs:727)

NullReferenceException: Object reference not set to an instance of an object Microsoft.MixedReality.Toolkit.Input.MixedRealityInputModule.UpdateMousePointerEventData (Microsoft.MixedReality.Toolkit.Input.MixedRealityInputModule+PointerData pointerData) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/MixedRealityInputModule.cs:252) Microsoft.MixedReality.Toolkit.Input.MixedRealityInputModule.GetMousePointerEventData (System.Int32 pointerId) (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/MixedRealityInputModule.cs:222) UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent (System.Int32 id) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/InputModules/StandaloneInputModule.cs:540) Microsoft.MixedReality.Toolkit.Input.MixedRealityInputModule.Process () (at Library/PackageCache/com.microsoft.mixedreality.toolkit.foundation@3bad99c89252/Services/InputSystem/MixedRealityInputModule.cs:161) UnityEngine.EventSystems.EventSystem.Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)

Your setup (please complete the following information)

Unity 2021.3.21f1 MRTK 2.7.3

Target platform (please complete the following information)

Happens on Windows and UWP

ongchef commented 2 years ago

I've got the same problem, it all works fine in a new project , anyone had the solution of it yet?

stef93 commented 2 years ago

Same problem here on 2.8.2. Manually copied all packages to assets and edited MixedRealityToolkit.cs as the suggested workaround.

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all-new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visit https://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!