One of the features of AR Foundation in Unity is Image Tracking. It’s one of the “oldest” methods to position virtual elements in the real world.
Is this still relevant today? Of course, it is! Markers are still helpful for the users because you can place them exactly where you want them to be. You can’t do this marker-less yet.
So, do you want to learn how to set up the project to use image tracking for AR?
Setup project 👨💻
You will have to install the following packages: AR Foundation, ARCore XR Plugin (for Android support), and ARKit XR Plugin (for iOS support).
Now we can start working. 🤓
The first thing we should do now is to set up the markers for our project.
To do that, go to the Project window and click Create > XR > Reference Image Library.
Now you have to import an image which you want to use as a marker. Add it to the newly created ReferenceImageLibrary object.
I would also recommend specifying the real-life size of the marker. If you have a print of it, just measure it on the paper.
Build AR scene 👨🎨
With every AR scene, we have to start by adding AR Session and AR Session Origin to the scene.
You can do it by going to the Hierarchy window and clicking Create > XR > AR Session and Create > XR > AR Session Origin.
Image Tracking 🖼
When you have both of them, you can add AR Tracked Image Manager to the AR Session Origin game object.
Of course, now we also have to assign the references in it.
One reference is for our ReferenceImageLibrary and the second one if for our prefab which will be displayed on the marker. Be aware that 1 unit in Unity space is 1 meter in the real world!
You can also specify how many images you want to track. The maximum number may vary between different devices so I would recommend checking it (read more).
Build settings 🛠
Depending on the platform you are using, you may want to change some build settings.
For Android, if your project requires AR support, you have to use at least API Level 24.
And for iOS, you will have to use at least iOS 11.0 and check “Require ARKit support“.
The result 🏆
And as you make everything correctly, now we can launch our AR app!
Great! It’s working! At least for me… 😅
If you don’t see the object there, your scale may be too big for AR, so try to walk away from the marker. 🚶♂️
If you find this useful, let me know in the comment section below or share it with your friend! I would really appreciate that! ❤️
And if you are interested in getting emails when I release new post sign up for the newsletter!
You can also check the whole project at my public repository. 🔗
See you next time! 🤓