Search Unity

Bug WINDOWS_UWP && UNITY_XR_WINDOWSMR not working?

Discussion in 'AR' started by herzogs, Dec 22, 2022.

  1. herzogs

    herzogs

    Joined:
    Aug 10, 2022
    Posts:
    6
    In my Application I want to scan a QR Code and spawn a Panel on top of it but I have 2 problems with the process..

    First of I use Unity 2021 with MRTK3 pre 12 and the QR tracking code is from here:
    MixedReality-QRCode-Sample/SpatialGraphNode.cs at main · microsoft/MixedReality-QRCode-Sample · GitHub

    Here is how I changed it:
    Code (CSharp):
    1. if (node == null)
    2.             {
    3.                 Debug.Log("InitializeSpatialGraphNode");
    4.                 node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null;
    5.                 if (node != null)
    6.                 {
    7.                     Debug.Log("Initialize SpatialGraphNode Id= " + Id);
    8.                     isNew = true;
    9.                 }
    10.             }
    11.  
    12.             if (node != null)
    13.             {
    14.                 if (node.TryLocate(out Pose pose))
    15.                 {
    16.                     // If there is a parent to the camera that means we are using teleport and we should not apply the teleport
    17.                     // to these objects so apply the inverse
    18.                     if (Camera.main.transform.parent != null)
    19.                     {
    20.                         Debug.Log("Pose before transformedby QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7"));
    21.                         pose = pose.GetTransformedBy(Camera.main.transform.parent);
    22.  
    23.                         // Rotate the panel so it faces the user
    24.                         pose.rotation *= Quaternion.Euler(180, 0, 0);
    25.                     }
    26.  
    27.                     if (isNew)
    28.                     {
    29.                         isNew = false;
    30.                         gameObject.transform.SetPositionAndRotation(pose.position, pose.rotation);
    31.                     }
    32.                     Debug.Log("Id= " + Id + " QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7"));
    33.                 }
    34.                 else
    35.                 {
    36.                     Debug.LogWarning("Cannot locate " + Id);
    37.                 }
    38.             }
    When I scan the QR Code my Panel with the SpacialGraphNode Script get spawned in (but always facing away from me? I don't know why but that's why the 180° rotation is in there) but it never gets a note so it can't position my panel. Adding some Debug texts reveals that I always end in the #else path wich just returns null all the time.

    If I change the #if WINDOWS_UWP && UNITY_XR_WINDOWSMR to just #if WINDOWS_UWP and switch to player I can see that the code should be reached but then I get an error saying that "WindowsMREnvironment" is not in "UnityEngine.XR.WindowsMR" maybe that is the problem?

    I tried running the App through Holographic Remoting and also building it and starting the app on the HoloLens itself. Has anybody an idea what the problem could be?


    Best regards
     
    Last edited: Dec 22, 2022
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062