Share via

How to fix "QR tracking not supported" error on Unity for hololens 2 dev?

Abhi Garlapati 1 Reputation point
2022-07-18T21:33:55.127+00:00

221977-qr-tracking-not-supported-error.png

This is the error I'm facing in Unity. I don't understand why the QRCodeTrackingService should fail. I have everything installed and formatted correctly.

Here is my sample scene:
221940-sample-scene.png

This error presents itself in the console of Unity. I'm not in play mode, it shows up in the console as soon as I open the project. I'm using the HoloLens 2, Unity 2020.3.7f1, and MRTK 2.6.1.

Code where error occurs:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using Microsoft.MixedReality.QR;  
using Microsoft.MixedReality.Toolkit.Utilities;  
using Microsoft.MixedReality.Toolkit;  
using MRKTExtensions.Utilities;  
using UnityEngine;  
  
namespace MRTKExtensions.QRCodes  
{  
    [MixedRealityExtensionService(SupportedPlatforms.WindowsUniversal)]  
    public class QRCodeTrackingService : BaseExtensionService, IQRCodeTrackingService  
    {  
        private QRCodeTrackingServiceProfile profile;  
        public QRCodeTrackingService(string name, uint priority, BaseMixedRealityProfile profile) : base(name, priority, profile)  
        {  
            this.profile = (QRCodeTrackingServiceProfile) profile;  
        }  
  
        public event EventHandler Initialized;  
        public event EventHandler<QRInfo> QRCodeFound;  
        public event EventHandler<string> ProgressMessageSent;  
  
        public bool InitializationFailed { get; private set; }  
        public string ErrorMessage { get; private set; }  
        public bool IsSupported { get; private set; }  
        public bool IsTracking { get; private set; }  
        public bool IsInitialized { get; private set; }  
        public string ProgressMessages { get; private set; }  
  
        private QRCodeWatcher qrTracker;  
        private QRCodeWatcherAccessStatus accessStatus;  
  
        private int initializationAttempt = 0;  
  
        private readonly List<string> messageList = new List<string>();  
  
  
        public override void Initialize()  
        {  
            _ = InitializeTracker();  
        }  
  
        private async Task InitializeTracker()  
        {  
            try  
            {  
                IsSupported = QRCodeWatcher.IsSupported();  
                if (IsSupported)  
                {  
                    SendProgressMessage($"Initializing QR tracker attempt {++initializationAttempt}");  
  
                    var capabilityTask = QRCodeWatcher.RequestAccessAsync();  
                    await capabilityTask.AwaitWithTimeout(profile.AccessRetryTime,   
                        ProcessTrackerCapabilityReturned,  
                     () => _ = InitializeTracker());  
                }  
                else  
                {  
                    InitializationFail("QR tracking not supported");  
                }  
            }  
            catch (Exception ex)  
            {  
                InitializationFail($"QRCodeTrackingService initialization failed: {ex}");  
            }  
        }  
  
        private void ProcessTrackerCapabilityReturned(QRCodeWatcherAccessStatus ast)  
        {  
            if (ast != QRCodeWatcherAccessStatus.Allowed)  
            {  
                InitializationFail($"QR tracker could not be initialized: {ast}");  
            }  
            accessStatus = ast;  
        }  
  
        public override void Update()  
        {  
            if (qrTracker == null && accessStatus == QRCodeWatcherAccessStatus.Allowed)  
            {  
                SetupTracking();  
            }  
        }  
  
        private void SetupTracking()  
        {  
            qrTracker = new QRCodeWatcher();  
            qrTracker.Updated += QRCodeWatcher_Updated;  
            IsInitialized = true;  
            Initialized?.Invoke(this, new EventArgs());  
            SendProgressMessage("QR tracker initialized");  
        }  
  
        private void QRCodeWatcher_Updated(object sender, QRCodeUpdatedEventArgs e)  
        {  
            SendProgressMessage($"Found QR code {e.Code.Data}");  
            QRCodeFound?.Invoke(this, new QRInfo(e.Code));  
        }  
  
        public override void Enable()  
        {  
            base.Enable();  
            if (!IsInitialized)  
            {  
                return;  
            }  
  
            try  
            {  
                qrTracker.Start();  
                IsTracking = true;  
                SendProgressMessage("Enabled tracking");  
            }  
            catch (Exception ex)  
            {  
                InitializationFail($"QRCodeTrackingService starting QRCodeWatcher Exception: {ex}");  
            }  
        }  
  
        public override void Disable()  
        {  
            base.Disable();  
            if (IsTracking)  
            {  
                IsTracking = false;  
                qrTracker?.Stop();  
                SendProgressMessage("Disabled tracking");  
            }  
        }  
  
        private void InitializationFail(string message)  
        {  
            SendProgressMessage(message);  
            ErrorMessage = message;  
            InitializationFailed = true;  
        }  
  
        private void SendProgressMessage(string msg)  
        {  
            if (!profile.ExposedProgressMessages)  
            {  
                return;  
            }  
            Debug.Log(msg);  
            messageList.Add(msg);  
            if (messageList.Count > profile.DebugMessages)  
            {  
                messageList.RemoveAt(0);  
            }  
  
            ProgressMessages = string.Join(Environment.NewLine, messageList.AsEnumerable().Reverse());  
  
            ProgressMessageSent?.Invoke(this, ProgressMessages);  
        }  
    }  
}  
HoloLens | Development
HoloLens | Development

The process of creating immersive mixed reality applications for Microsoft HoloLens,


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.