Augmented Reality Tutorial (all new for 2022!) (Patreon)
Content
Hi folks,
A few years ago, I made a tutorial about augmented reality (AR) using the Unity game development engine and a third party service called Vuforia. Several patreons have gotten in contact recently wanting to use AR in an escape room and asked if I could update that project, since it had gotten a little out-of-date.
So, I'm pleased to say here's a new tutorial which is based on the latest version of Unity 2022. Although the end result may seem similar to that created in the previous project, the process is actually totally different - I no longer use Vuforia, but rather Apple and Google's native AR libraries - which means that you don't have to rely on a third-party service, the app is totally self-contained on an Android/iOS device, there's no limits on the amount of anchors you can track, and there's no issues with watermarks etc.!
There are many Augmented Reality projects you can create, that essentially differ based on the (real) object you want to track, and the (virtual) object you want to position based on it:
"Trackable" objects in the real world include any textured surface, a 3d shape, a person's face or body, or a floor, ceiling, or wall.
Virtual objects that can be anchored to those tracked objects can be images, videos, or (animated) 3d models. And those objects can themselves be interactable.
The project I create in this tutorial is capable of combining any number of those real and virtual objects. So, for example, if you used this app on a device in your room, you could have:
a photograph or painting of a person that changed into an animated movie clip and spoke to you when viewed through the AR app (similar to Harry Potter portraits, or the labels on bottles of "19 Crimes" wine)
a "haunted" object inhabited by ghostly spectres that only became visible when viewed through a special AR "spectral analyser"
a statue that became animated as a 3D model
a playing card that changes into another suit, as an AR magic trick!
There is potentially a *huge* amount of detail to cover, so I've tried to keep the video to only walk through how you'd create the most requested use-case, which was to detect an image (a playing card) and replace it with another image or video. But if you have specific questions about some of the other examples I demonstrate, please do ask!
You can find documentation about Unity's AR Foundation (the "wrapper" that Unity provides to access the functionality of Google ARCore and Apple ARKit) at https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@5.0/manual/index.html
You can download the C# script that manages the prefab objects associated with each tracked image from https://gist.github.com/alastaira/92d790ed09330ea7a45e7c3a2a4d26e1 - simply place this anywhere in the "Assets" of your project, and attach it to the gameobject in your scene that has the AR Origin and AR Tracked Image Manager component.