Hello everybody! This article has been long overdue and most requested as well. I thought it would be also a good opportunity to combine this with how to use the latest XR plugin that replaces the Legacy XR with the advent of Unity 2020.x versions.
In this article, we will see a tutorial on how to do QR code scanning and tracking with the new XR SDK and MRTK v2.5.x and of course, Unity 2020.x version. If you have seen my articles before, I always use the penultimate release of MRTK, simply because the latest one will not yet be stable and could be buggy. Therefore, the MRTK v2.5.
Let’s get started!
1. Get Unity 2020.x version. I have specifically used, 2020.2.1f1, also because its not too recent and higher likelihood of it being more compatible with the MRTK and the code that we write as well. AFAIK, the QRcode tracking code that I have used to refer was tested successfully on Unity 2020.x versions. Feel free to use latest versions and let me also know if that works with this code here 🙂
Create a new 3D project as usual.
2. Get MRTK v2.5: Specifically, I have used MRTK v2.5.4, we can get this with the new Mixed Reality Feature Tool which was out early March, this year. The link to download is here: https://www.microsoft.com/en-us/download/details.aspx?id=102778 Once you have downloaded, open the MixedRealityFeatureTool.exe and you will see a screen
If you want to configure it in a specific way, see here. Else, just click on Start.
In the next screen, provide the location of your project path
It should automatically pick up your project version as well.
Then click on Discover Features. It should show you standard packages which we may need for MRTK. For this project, we would need:
Mixed Reality Toolkit Foundation v2.5.4
If there are any dependencies we need, the tool will automatically recommend the needed packages. In this case, it needs the Standard Assets package as a dependency.
You could here click on Import or Validate. Although the recommendation by MRTK guys is to click Validate– so that we can see if anything went wrong in the pop up dialog later. When no issues, click on Import.
The next screen will be a Review and Approve. Click on Approve.
The final screen will be that the project has been successfully updated. If you go to your project now in Unity, it will refresh and load all those packages.
3. Now for the XR SDK: Go to Player-Project Settings and under XR Plugin Management, click on Install XR Plugin Management. This will take a few minutes and install the XR SDKs into your project
Switch to the Windows Platform and enable the Windows Mixed Reality option. This again takes a few minutes to install the WindowsMR plugin into your project. Also make sure that Initialize XR on Startup is enabled.
4. Click on Mixed Reality Toolkit at the top and click on Add to Scene and Configure. This will add the Mixed Reality essentials to the project such as the Playspace and the Toolkit. We need to configure the MRTK to run with XR SDK. For this, choose DefaultXRSDKConfigurationProfile as the active profile.
Also clone the SpatialAwarenessProfile – XR SDKWindowsMixedRealitySpatialMeshObserver and set the Display Settings–Display Option to None.
Ok, So we are now done with setup.
For the QRCode part:
Let’s make a simple UI panel which can start and stop QR code tracking with the help of a button. I won’t cover the UI panel in this tutorial. You can use the Pressable Button prefab that MRTK provides and make your own. I also have the latest QRCode scanned data shown in this panel- so that we get visual feedback directly within the app.
For the QRCode part, here’s where I started off with it:
I also looked at the Sample QR Code app here:
https://github.com/chgatla-microsoft/QRTracking which was really helpful in showing how this is done. It also provides some prefabs and scripts which I reused such as QRCodesManager, QRCode.cs, QRCodesManafer.cs, QRCodesVisualizer.cs, etc. Whatever I have reused, I put them in a folder called QRCodeStuff in the project.
First, we need the Microsoft.MixedReality.QR package. This can be installed via Nuget for Unity. I downloaded Release 3.0.1 which is latest at this time. Once you have downloaded it into your PC, go to Assets-Import Package-Custom Package and navigate to where you saved Nuget package and import into your project.
Then you will see a menu item called Nuget when it has been successfully imported. Click on Manage Nuget Packages and search for Microsoft.MixedReality.QR package and install it.
Once successfully installed, you will see the package in Assets-Packages
So now in your scene, drag and drop the prefabs QRCodePanel and QRCodesManager. Note here that you need all those prefabs, scripts and materials which I have in the QRCodeStuff folder. Else, it breaks.
If you get a popup to Import TMP essentials, do it- as this is needed for the text items on QRCodePanel
Now in the QRCodesManager Inspector view, drag and drop the QRCode prefab into QRCodePrefab of QRCodesVisualizer
Drag and drop the LatestQRCodeDetails into the LatestQRCodeDetails field of QRCodesVisualizer
Make sure AutoStartQRTracking is disabled as we want to trigger the scan and stop it via our own script. I will come to this in a bit…
To explain a few prefabs and scripts(these were used from the sample project indicated earlier as well)
QRCode: This is a prefab with a transparent Quad and an axis on the top left corner of the Quad to show the coordinates and the QRcode area whenever a new QRCode is scanned or updated. This is especially useful, when you want to perform tracking of the object with a QRCode on it.
QRCode itself has two scripts on it:
QRCode.cs: It shows what goes into a QRCode such as its unique ID, data, text, version, timestamp etc. It also has a NodeID which is used for the coordinate identification part. Therefore, this script requires the SpatialGraphCoordinateSystem.cs which does all of these coordinate calculations.
The QRCodesManager script comes with its own StartQRTracking() and StopQRTracking() functions. We can call these directly when we press the StartScanButton and StopScanButton respectively. But to keep it neater, I will just create a new script which does that for us. I also will update the StatusText to inform us that QRCode scanning has started and stopped accordingly. Let’s call this script MyQRCodeManager.cs
It will be a simple script with two functions used to start and stop scanning and to change the StatusText.
The code is shown below.
Add an empty GameObject to the scene and call it Manager. To it add the MyQRCodeManager script.
It has two public variables qRCodesManager and statusText which we will assign to the QRCodesManager prefab which contains the QRCodesManager script and the statusText in our QRCodePanel
Let’s have a look at QRCodesManager script again.
For your ease of understanding, I have added in comments to explain the code better.
Looking at the Start() method, we first need to check if QRCode scanning is supported on the device that we use. Thankfully for us, this is in the QRCodeWatcher script with IsSupported(). Then we need to get a reference to the QRCodeWatcher class and call the RequestAccessAsync() on it which gets us the permission to use the webcam.
Once these are checked and there are no errors, we set the accessStatus and capabilityInitialized to true. These will be used later.
The next function to look at is the SetupQRTracking():
Here, we will initialize to check if the tracker is already running via a variable IsTrackerRunning.
Next, we will subscribe to events to alert us whenever a QRCode is added, updated, removed and enumeration completed. Enumeration completed is used to maintain a list of QR Codes which we add in the same session.
So now, returning to MyQRCodesManager, let’s assign the start and stop functions to the button pressing accordingly.
We want to be able to do three things when we press the StartScanButton:
1. Call the StartScan() function on MyQRCodeManager
2. Don’t show the StartScanButton
3. Show the StopScanButton
Do all of these accordingly with the OnClick() event on the button
We also need to do three things when we press the StopScanButton:
1. Call the StopScan() function in MyQRCodeManager
2. Show the StartScanButton
3. Don’t show the StopScanButton
Now if we look at the flow of our code:
when we press the StartScanButton, the StartScan() function in MyQRCodeManager calls the StartQRTracking() function on QRCodesManager.
Simultaneously, the QRCodesVisualizer script sets up its dictionary to maintain QRCodes. It also subscribes to the events on adding, updating, removing, so that the visualizer can act accordingly.
You will notice in the Update() method, it calls HandleEvents() which will based on the corresponding event- such as updating of QRcode, removing or adding will handle the visualization and data change accordingly.
There are more comments within the scripts to explain what the code does.
In line 112 of QRCodesVisualizer, we also will update our LatestQRCodeDetails text to show the data of the most recent QRCode scanned.
If you do have any more questions about what the code does in these scripts, do let me know.
Don’t forget to add following capabilities to detect QR Codes and visualize them correctly
Webcam
InternetClient
SpatialPerception
GazeInput
Microphone(optional – if you use speech commands to control the starting and stopping of scanning)
Ok, so now that we have all setup, let’s build and try it out!
I also noticed that XR SDK builds are much faster! I don’t know if this was a feature of Unity 2020.x or the XR plugin.
So, I tried 3 different QR codes with different sizes and resolution. One with 300 px and 7x7cm size, one with 200 px and 4x4cm size and one with 300 px and 2x2cm size
1. The bigger and closer you are to the QRCode, the faster it gets recognized. 2x2cm does not get recognized.
2. Gets detected in good lighting conditions, I tried in twilight time and it was working well even with little light
3. This point is specifically important on how to manage QR codes from the Microsoft page here:
Managing QR code data
“Windows Mixed Reality devices detect QR codes at the system level in the driver. When the device is rebooted, the detected QR codes are gone and will be redetected as new objects next time.
We recommend configuring your app to ignore QR codes older than a specific timestamp. Currently, the API doesn’t support clearing QR code history.”
You can see the detailed best practices for QRCode tracking with Hololens2 here
I also noticed that the tracking is slower, so it takes a few seconds to get adjusted to the new positions of the QRCode. But this is not a deal breaker 🙂
The project code is in GitHub here: https://github.com/NSudharsan/HoloLensExamples/tree/master/QRCodeXRSDK
Below is the output video:
I’m not sure why the video output shows that the QRCode displacement by a few cms. In the Hololens View, its perfectly on the QRCode.
By the way, I have tried this code with Legacy XR and it also works. The only change I had to make was in SpatialCoordinateSystem.cs. Comment out the XR related lines on 75 and 76 and add line 77,78. Thanks to Edd Smith from the HoloDevelopers Slack Community who gave me this solution!
Hi Nischita, nice article, have one question, do you know when the other events like qr code removed and updated is called. I understand that qr code added event is called when I bring a qr code in front of hololens camera but couldn’t understand when the other events like remove and update is called
Hi Rajendra, The QRCodeAdded event is called whenever the system detects the QRcodes for the first time. QRCodeUpdated event is called each time the QR code location is changed (only applies to previously detected QRCodes). The remove event is called when you want to call it 🙂 i.e imagine a situation where you want to have a timer of 5 min and remove all those QRCodes detected before that timer. Then you call the QRCodesRemoved event. Hope that helps!
Hi !
Thank you for this post, it was vrey usefull.
I have some questions for you:
– I do not understand how the Hololens succeed to replace QRCode prefab in the location and position in the space even if I move at the start of the app and even if I unistall and install thre app. I think with what I saw in scripts it is because the app scan and place in function of the environment but I am not sure.
-Do you think it is possible to place gameobject in fuction of the location of the QRCode prefab? If yes, how because I tried without successe.
Thank you for everything.
Hi Auguste, Glad to help! To answer your questions:
– The QRCodes with the Hololens are detected at OS level. What that means is the device remembers the QRCodes previously scanned unless you reboot the device itself. Then the QRCodes previously detected would be removed from OS level. Uninstalling the app does not help in resetting QRCodes to not scanned. So if you want the app to work in a way that you trick it to only scan QRCodes when you start the app, have a timer or so and only show those QRCodes which you have detected in the last 5 min or so…
– Yes, this is possible. Just use the transforms on the qrCodeObject in the QRCodesVisualizer.cs and instantiate your object in the same location, rotation or scale of the QRCode detected.
First of all a huge thank you for your website and your articles it’s really very useful for novices like me.
I use your QRcode Tracking example to create an HL2 application, but I have a problem I slightly modified the QRcode prefab and the associated script to display the coordinates of QRInfo;
and I would like to get the coordinates of the QRcode to be able to create 3D objects positioned according to this QRcode.
I saw that in the script SpatialGraphCoordinateSystem.cs there is a local variable of the function UpdateLocation which gives the position and the rotation of the QRCode.
I thought that it was possible to recover these local variables and to pass them in “global” in order to transmit them to another script (script which creates my 3D objects).
Unfortunately I don’t know how to do it, I tried to make a getter/setter but I’m not sure how to call this getter from another script.
Could you help me ? I am completely new to C# and unity so sorry if my question is stupid.
First of all a huge thank you for your website and your articles it’s really very useful for novices like me.
I use your QRcode Tracking example to create an HL2 application, but I have a problem I slightly modified the QRcode prefab and the associated script to display the coordinates of QRInfo;
and I would like to get the coordinates of the QRcode to be able to create 3D objects positioned according to this QRcode.
I saw that in the script SpatialGraphCoordinateSystem.cs there is a local variable of the function UpdateLocation which gives the position and the rotation of the QRCode.
I thought that it was possible to recover these local variables and to pass them in “global” in order to transmit them to another script (script which creates my 3D objects).
Unfortunately I don’t know how to do it, I tried to make a getter/setter but I’m not sure how to call this getter from another script.
Could you help me ? I am completely new to C# and unity so sorry if my question is stupid.
Hey Oceane, just access the qrCodesObjectsList from your other script. One way is to make that public and access it via getter and setters. You could watch this video to understand getters and setters in c# https://www.youtube.com/watch?v=-Bgt6HJEhf0
Hey Nischita,
For a project at our University we need to scan QR-Codes to switch in differnt scenes.
First of all: is this possible?
Moreover, we try to implement your how to. Unfortunately we can’t find the QRCodePanel and the QRCode_icon within the proposed download folder on GitHub.
It would be great if you could help us getting our problem solved.
Yours Sincerely,
Ramon
Hey Ramon, What do you mean by scanning QRcodes to “switch in different scenes?” The prefab and icon are in here: https://github.com/NSudharsan/HoloLensExamples/tree/master/QRCodeXRSDK/Assets/QRCodeStuff
Best, Nischita
Hi Nischita,
thank you for your support. We now got the right files.
But there came a new problem up. We are trying to assign the start and stop functions from the “StartScanButton”. But we can´t see the Onclick()-Event.
Do you have an idea why there is only Touch Begin () and Touch End() etc.?
Thank you very much in advance.
BR
Ramon
Hey Nischita,
thank you, not it worked.
But we´ve got a new problem now. We would like to support a gripper change for a small robot with the Hololens. For this we would like to use two QR codes (for two different grippers) that show the user which gripper is currently mounted.
By using your instructions, we are unfortunately only shown the link to the associated website after successfully scanning the QR code so far. Do you have any idea how it could be possible to switch to a new scene by scanning the QR code? So that our programme jumps to the corresponding next scene depending on the scanned gripper? I hope you now understand our problem better and can help us.
BR
Ramon
Hi Ramon, first, you could configure the data of the QRCode to be a scenename. Next, access the action.qrCode.Data and then use SceneManager.LoadScene to jump to the next scene. Details here: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html You could also look at this older article here on how to change scenes. The basic idea is the same: https://codeholo.com/2018/07/31/changing-scenes-and-viewing-ui-elements-rightly-in-hololens-apps/
Hi Nischita,
I do not know why but I cannot post under my first comment.
I just want to say thank you for helping me, it allows me to finish my application. Sorry to respond just now but when I managed to read QRcode I was to concentrate on my project that I have forgotten to say thank you.
I wish a great continuation
Auguste
Hello Auguste, Glad that this helped you. 🙂
best, Nischita
Hi Nischita! thanks so much for this amazing guide, I managed to make it work thanks to you! I am now wondering where i should go to look for where the QRCode,Data is stored? i am having a few issues finding it. I essentially want to be able to specify which QR codes should make the program react and produce something and which QR codes should be ignored (so i’m hoping to specify a string that the QRCode.Data should look for)
if this is probably the wrong way to do it though please let me know. Your help is much appreciated.
Hi, check the article for the section on looking for In line 112 of QRCodesVisualizer, adding LatestQRCodeDetails text to show the data of the most recent QRCode scanned. This is the QRcode data.
Hi Nischita,
Do you know if this will work using OpenXR instead of the Windows Mixed Reality? (Under XR Plug-in Management)
Yes it does. Have tried it. See my article on Open XR: https://codeholo.com/2021/07/16/migration-of-hololens2-projects-to-newest-mrtk-v2-7-2-and-open-xr-sdk/ and the special section therein which shows you what adjustments you need to make to get QRcode SDK OpenXR compliant. (scroll down to the end)
Hey Nichita!
Your tutorial helped a lot. I now want to implement a reset button that would delete all scans along with the prefabs associated with them, but when I did that, the scanner would not scan the QR codes again and when I stop and start the scanning it doesn’t help and the old QR codes pop up once again. Could you help me perhaps?
My reset function clears both SortedDictionary’s in the visualizer and manager.
Hey there Ari, I’m glad the tutorial helped you. So the QRcode scanning from Hololens is done at an OS level- that means that the QR codes are detected and remain there unless you physically reboot your device. There is nothing we can unfortunately do about it. so those squares will appear even when you stop scanning. What you can do is show only those until a particular timestamp. https://docs.microsoft.com/en-us/windows/mixed-reality/develop/platform-capabilities-and-apis/qr-code-tracking see here the section on Managing QRcode data
Hey,
I want to be able to delete a QR Code after i scanned it and then rescan it. I see there is a RemoveQRCode function but I couldn’t figure out how to call it. Can you help me do so?
Please see my response to your previous question. hope it helps
Hi,
Thanks for this great write up and sample code! I was wondering if you happen to have a .appx file you could share so that I might test on device without building? I’m getting some errors when trying to build (likely some problems on my side with settings). Rather than debug and get it working, if you had a build you could share, that would save me a bit of time 🙂
Hey John, is there some place like Dropbox or so which you can set up? then I can load the appx there.. Also, I could help you out with your build settings- if you send me a screenshot to codeholo@gmail.com
Thank you so much for this tutorial!
I am currently trying to do something similar to what Savary Oceane mentioned, and I need to extract the spatial coordinates of different QR Codes that were detected.
I looked at the codes in QRCodesVisualizer.cs and it seems like the qrCode.SpatialGraphNodeId and the qrCode is saved inside the qrCodesObjectsList which you mentioned above.
However, I am not sure how I can get the spatial coordinates of the QRCode.
-Is it saved in the qrCode.SpatialGraphNodeId or the qrCode?
I thought it was saved in the qrCode.SpatialGraphNodeId judging from this website, https://docs.microsoft.com/zh-tw/windows/mixed-reality/develop/native/qr-code-tracking-cs-cpp#qr-code-tracking-api-reference
but my qrCode.SpatialGraphNodeId looked like this: ”f32e1f59-f0ff-45f6-8312-fd78cba56414,” and I am not sure how to convert it into spatial coordinates.
-If I was wrong and it is actually saved in the qrCode.SpatialGraphNodeId, what function should I call to extract the spatial coordinates information from the qrCode?
Thank you so much for this tutorial!
I am currently trying to do something similar to what Savary Oceane mentioned, and I need to extract the spatial coordinates of different QR Codes that were detected.
I looked at the codes in QRCodesVisualizer.cs and it seems like the qrCode.SpatialGraphNodeId and the qrCode is saved inside the qrCodesObjectsList which you mentioned above.
However, I am not sure how I can get the spatial coordinates of the QRCode.
-Is it saved in the qrCode.SpatialGraphNodeId or the qrCode?
I thought it was saved in the qrCode.SpatialGraphNodeId judging from this website, https://docs.microsoft.com/zh-tw/windows/mixed-reality/develop/native/qr-code-tracking-cs-cpp#qr-code-tracking-api-reference
but my qrCode.SpatialGraphNodeId looked like this: ”f32e1f59-f0ff-45f6-8312-fd78cba56414,” and I am not sure how to convert it into spatial coordinates.
-If I was wrong and it is actually saved in the qrCode.SpatialGraphNodeId, what function should I call to extract the spatial coordinates information from the qrCode?
Thank you so much for this tutorial!
I am currently trying to do something similar to what Savary Oceane mentioned, and I need to extract the spatial coordinates of different QR Codes that were detected.
I looked at the codes in QRCodesVisualizer.cs and it seems like the qrCode.SpatialGraphNodeId and the qrCode is saved inside the qrCodesObjectsList which you mentioned above.
However, I am not sure how I can get the spatial coordinates of the QRCode.
-Is it saved in the qrCode.SpatialGraphNodeId or the qrCode?
I thought it was saved in the qrCode.SpatialGraphNodeId judging from this website, https://docs.microsoft.com/zh-tw/windows/mixed-reality/develop/native/qr-code-tracking-cs-cpp#qr-code-tracking-api-reference
but my qrCode.SpatialGraphNodeId looked like this: ”f32e1f59-f0ff-45f6-8312-fd78cba56414,” and I am not sure how to convert it into spatial coordinates.
-If I was wrong and it is actually saved in the qrCode.SpatialGraphNodeId, what function should I call to extract the spatial coordinates information from the qrCode?
Hi Tiffany, the spatial coordinates are just the transform.x, transform.y and transform.z on the Qr code itself.
Sorry for leaving so many replies >_<
I thought my replies were regarded as trash by the system and was deleted.
Thank you so much for sharing your work and answering my questions, it is all very clear and it helped me so much!!!
Thanks for the guide. When I try to build the UWP app I get the following error:
Assets\QRCodeStuff\SpatialGraphCoordinateSystem.cs(75,60): error CS0234: The type or namespace name ‘WindowsMREnvironment’ does not exist in the namespace ‘UnityEngine.XR.WindowsMR’ (are you missing an assembly reference?)
Hi, This is because you are using a version of Unity which does not support WIndows MR. I guess it supports OpenXR. Then pls look here to update the APIs: Reference: https://github.com/yl-msft/QRTracking/tree/main/SampleQRCodes/Assets/Scripts
Make sure you follow the GitHub link above to get all the scripts and prefabs etc necessary for QRCode Tracking with Hololens 2. The main changes although were in SpatialGraphNodeTracker instead of the SpatialGraphCoordinateSystem.cs
Thankyou for such a nice article.
Also I am I’m trying to use the Microsoft.MixedReality.QR in order to make a continuous detection of a QRCode on Hololens V2. Imagine having a QRCode sicked to your hand and a 3D model following it, that’s the idea.
But it looks like this lib doesn’t meant to be use this way. Indeed, the detection update event are fired at a “chaotic” rate and the received positions are late compared to the real QRCode one. I want to detect the qrcode once and when I am moving the qr code at the same time I want to see my model moving in HoloLens 2 . Where to make change in the Script. Please do help ? Thanks.
Hi Nitesh, you just change the transforms on the model to match the transforms on the QR code as soon as the Qr code is added.
Best, Nischita
Hello Nischita :-), first of all a big thank you for this great tutorial! Unfortunately, the build file doesn’t work as expected for me. I see the QR panel on the HL2 after starting the app. I can also start the scan function, but no QR code is found, no matter how long I look at the QR code. In addition, after I clicked the scan button, I did not see that the scan had started. Do you have any idea what I did wrong? Maybe you could provide me with the finished build? You could put the file in my Dropbox folder.
https://www.dropbox.com/sh/c9hjx4eapg2725d/AABmav03MT5cXlW40NpfoHTEa?dl=0
Thank you for the great work!
Hi, You could send me a screenshot of your inspector settings to see how the project is configured and maybe then I can say more 🙂
Email at codeholo@gmail.com
Best, Nischita
Hello All, I am able to generate a model using QR Code scan in MRTK 2.7.3. In first time it works fine but the problem is when I am restarting the app again and again in my hololens 2 then the model is not stable,it jumps or shake. I used both OpenXR and Windows Mixed Reality Plug-in. But not able to fix it. Is there a solution to fix it ?
Hi, If the model is not stable then there may be several reasons:
-are you using a lightweight 3D model- what is the size and polygon count?
– Did you try anchoring your model when you first generate it? Anchors help ground your model to the right location so that jitter problems are avoided
I tried to follow you But now the problem is QRcode prefab not follow qrcode when qrcode is changed location. QRcode prefab still in the same position (maybe 0,0,0)
I tried to follow you, qrcode can be scanned. but i found a problem. QRcode prefab not change position when my QRcode is changed. It’s still in the same position (maybe 0,0,0). I’m not sure what happen.
Hi Nischita, it’s me Tiffany. I am currently trying to move the QRCode by pressing a button on the QRCodePanel but I am encountering some problems.
My steps are as follow:
1. Create a script in QRCodesManager for moving QRCode.
2. Create a Moving Button by duplicating the StartScanButton.
3. Set the OnClick() of the button into evoking the move function in the moving script.
The steps are quite simple, however, nothing happens when I hit the Moving Button.
Do you have any clue about what might be causing the Move Button to malfunction?
Appreciate your assist and time!
Hi Tiffany, The QR code automatically comes with tracking feature. What is the use case behind moving the QR code? The QR code prefab itself reacts to the automatic tracking, so if you want to move the QR code prefab then you need to disable tracking as soon as it is detected. Best, Nischita
Failing to run this QRCode demo under OpenXR since 3 days, but I agree that the basic menu functions. OpenXR is not able to use Windows XR specific features ? Alternatively a sample would be great please !
Hi, OpenXR will not use Windows MR features. I have made that work with openXR. Make sure you read this article: https://codeholo.com/2021/07/16/migration-of-hololens2-projects-to-newest-mrtk-v2-7-2-and-open-xr-sdk/ the last part where it explains how you need to make your QR code work with OpenXR as well. Best, Nischita
(Also tried your migration tutorial without success)
What is the error you are getting? can you make a screenshot and send it to codeholo@gmail.com – I can take a closer look there
Thank you for your instant reply. My initial intension was to create a button that could change the position of another object. But the button could not work whenever the “start scan” button is pressed, though it can function after I press the “stop scan” button. I really want want to figure out why this is happening. Thank you again for your help.
Maybe you can add some debuggers to your Onclick() event on the button that you try to press. It’s hard to say without having a look at the Unity application.
Hi Nischita, thankyou for such a nice article.
Also, I am trying to put a 3D model into the QRCode prefab and display this model using QR Code scan, it’s work, but when I create a script to hide some parts of my model by Onclick() button when start scanning, the model can not hide the parts I selected, the display model always shows the origin model.
-Do you think it is possible to hide the parts of the 3D model when starting scanning? I use the Gameobject.SetActive(false) and GameObject.GetComponent().enable false these two ways to hide the model but it can’t work.
Hi Robert, I need to see the Gameobject whose parts you are trying to hide.. If I understood you correctly? Maybe you can send a screenshot at codeholo@gmail.com
Hi Nischita, I’m tryng to implement the QR detection in my app. I tested example in your link and i didn’t have problems, All worked fine. The problems begin when i try to migrate the code in another project. It seems that QRCodeWatcher.Add it’s never fired when you look a QrCode. I’m spending a lot of time on that, Hope you can give me some suggestion. Thanks.
Hi Nishita. I’m pretty new on hololens programming with unity and hololens. Now i’m trying to integrate in an existing Application an Qr detection functionality. I’m following Official demo and i have no problem on it, all work fine. Problems start when i try to integrate the code in the existing project. It seems the QRCodeWatcher Class never fire Added event when i look a Qrcode. I have no idea on the cause of this. Can you give me some suggestions?
I’m using mrtk 2.7.2 and unino 2020.3.30.
I was able to get the code to build, but when a QR code is detected, a stationary purple coordinate system is placed at the origin. The coordinate system doesn’t move at all. The main change to the environment I made was unchecking the RadialView from the QRCodePanel.
As a side note, is the code provided in the GitHub link the same code that was used in the video? It seems that the QRCodePanel in the video doesn’t use RadialView because it is stationary in worldspace, but the provided code has the QRCodePanel fixed relative to the HoloLens, which means it moves with the HoloLens.
Hi, when you unpin it the panel would move as RadialView is then automatically checked. The code is exactly the same in both cases. If you are using Unity versions > 2021.x make sure you use Open XR compatible APIs: Reference: https://github.com/yl-msft/QRTracking/tree/main/SampleQRCodes/Assets/Scripts
Make sure you follow the GitHub link above to get all the scripts and prefabs etc necessary for QRCode Tracking with Hololens 2. The main changes although were in SpatialGraphNodeTracker instead of the SpatialGraphCoordinateSystem.cs
Thank you for helping. I tested it following you, but my hololens2 see the QR code, nothing happens. I can’t find qrcode prefab.. . … and i changed this code ( //System.IntPtr rootCoordnateSystemPtr = UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem;
//SpatialCoordinateSystem rootSpatialCoordinateSystem = (SpatialCoordinateSystem)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(rootCoordnateSystemPtr);
SpatialCoordinateSystem rootSpatialCoordinateSystem = (SpatialCoordinateSystem)System.Runtime.
InteropServices.Marshal.GetObjectForIUnknown(UnityEngine.XR.WSA.WorldManager.GetNativeISpatialCoordinateSystemPtr());)
there is an error. Assets\QRCodeStuff\SpatialGraphCoordinateSystem.cs(78,66): error CS0234: The type or namespace name ‘WorldManager’ does not exist in the namespace ‘UnityEngine.XR.WSA’ (are you missing an assembly reference?) Can you help me?
i followed your guide, but my hololens2 can’t find qr code and it did not work prefab…
start button works well, but i see the qr code, nothing happens..
Hi ,Are you using Open XR settings and new APIs for correct QR code tracking. Reference: https://github.com/yl-msft/QRTracking/tree/main/SampleQRCodes/Assets/Scripts
Make sure you follow the GitHub link above to get all the scripts and prefabs etc necessary for QRCode Tracking with Hololens 2. The main changes although were in SpatialGraphNodeTracker instead of the SpatialGraphCoordinateSystem.cs
Good morning,
First of all thank you very much for your explanation, it was really helpful and quite clear.
I wanted to ask you if you could tell me why the detected QR code continues to appear even if it stops appearing in the field of view of my HoloLens. I’ve tried in several places to make the GameObject inactive with the corresponding ID, but I can’t manage to do it in the right place in the code. Could you please help me? Thanks in advance.
Good morning,
First of all thank you very much for your explanation, it was really helpful and quite clear.
I wanted to ask you if you could tell me why the detected QR code keeps appearing even if it stops appearing in the field of view of my HoloLens. I’ve tried in several places to make the GameObject inactive with the corresponding ID, but I can’t manage to do it in the right place in the code. Could you please help me? Thanks in advance.
Hi Paula, As I have mentioned in the article- QR codes are detected at OS level on the Hololens 2- so even if your application is stopped, the QR code keeps showing up until you restart your device. YOu could provide a timer or so to show QR codes if it’s scanned older than x amount of time or so.
Hi Nischita,
many thanks for your nice guide!
I tried set up a project following your guidelines but it doesn’t detect any QR code I look at (I tried with 5 different ones). Looking at the log messages everything is set up correctly, but no event is called when I look QRs. Any idea on how I can solve this problem?
Thank you in advance for your help!
Mattia
HI Mattia, did you check if the capabilities are set? Webcam? Also if it’s OpenXR i.e > Unity version 2021.x then- make sure you refer to the new APIs that it brings. Reference: https://github.com/yl-msft/QRTracking/tree/main/SampleQRCodes/Assets/Scripts
Make sure you follow the GitHub link above to get all the scripts and prefabs etc necessary for QRCode Tracking with Hololens 2. The main changes although were in SpatialGraphNodeTracker instead of the SpatialGraphCoordinateSystem.cs
Hi Nischita, thanks a lot for the article, it’s really useful! I’m trying to put a GameObject in the same location as the QR code, but it’s not working for me unless I attach an SpatialGraphCoordinateSystem to it. Is there a way to make it work by using the transform.position? I’m using:
tempModel.transform.position = new Vector3(qrCodeObject.transform.position.x,
qrCodeObject.transform.position.y,
qrCodeObject.transform.position.z);
Thanks!
Hey Nischita,
At first, thank you for this very good and detailed tutorial. It helps me a lot!!! I’m currently coding an AR-App for Robots in Unity and I want to use the tips of your example to place a virtual Robot on a table. I got an error with the QR-Codes Manager Script. The compiler throws me the error in line 85 “accessStatus = await capabilityTask;”. So the error comes with the await of the async Task, but why?? :-/ Do you have the same error?
Hi Nischita,
Thank you for such a cool example. I have this qr code tracking working pretty fine.
But I have one more thing I want to do, that is to remove the qr code after being tracked lets say 1 minute relative to the current time.
Could you please help on where to start with I am bit confuse?
Hi Nischita,
When I run the project the axis are spawned at the origin and not in the top left corner of the scanned QR code. Do you have any solution for this problem?
Thanks
Aa