Home Creators Posts Import Register Favorites Logout

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. 

Files

Augmented Reality (AR) tutorial for beginners using Unity 2022

This is a step-by-step tutorial illustrating how to create an Augmented Reality (AR) app for an Apple iOS device or Android mobile phone or tablet, using the latest version of Unity 2022. Augmented Reality is the technology you may have seen in games like Pokemon Go!, Harry Potter: Wizards Unite, Snapchat filters, or home design apps that let you superimpose virtual objects on a video feed that track the location of objects in the real world. Unlike QR codes or barcodes, I'll show you how you can use image tracking that will detect the texture of any flat object - a poster, the page of a book, an album cover - and place a new image, object, or movie on top of it. I'll be using the Unity AR Foundation combined with native functionality on the device - Google ARCore on Android or Apple ARKit on iOS, to create a completely standalone app, with no internet access or third-party components required. And you can make it and deploy it yourself, completely for free, by downloading Unity from www.unity.com Timings --- 00:00:00 - 00:03:05 Introduction and example applications 00:03:06 - 00:05:41 Downloading and installing Unity engine and modules 00:05:42 - 00:10:24 Creating and configuring the Unity AR project 00:10:25 - 00:12:36 Core components in an AR scene 00:12:37 - 00:15:16 The AR Tracked Image Manager 00:15:17 - 00:24:05 Adding custom functionality using C# script 00:24:06 - 00:26:26 Creating a simple AR gameobject prefab 00:26:27 - 00:27:34 Deploying the app to a device 00:27:35 - 00:30:35 Creating AR video clips or animated 3D models 00:30:36 - 00:32:10 Wrapup For more information about this, or to access the downloads and resources for any of my other tech projects featured on this channel, please head over to https://www.patreon.com/playfultech

Comments

Jason Hayhurst

I have followed this and have used a plane prefab to then add an image to replace on detection. When I test I just get a flicker of the image and nothing. Any idea why?

Christer Sten

When adding the script with the array that is supposed to store the replacement images to AR Session Origins I only get a script error. The script is copy pasted from your github page and saved as a .cs file. "The associated script can not be loaded. Please fix any compile errors and assign a valid script"

Janson Prieb

Hey Alastair, I've done everything you did on the tutorial, but I'm failing to augment my play card. I've checked all the settings, coding, labels are correct, everything I can think of. I'm running it iOS.

Avery

Hey Alastair (if you saw my previous message before I deleted it no you didn't!) I have managed to get the app working however the orientation and scale of my AR element is super wack -was wondering how to adjust it or if you can point me in the direction of a tutorial of understanding perspective in unity -> this is my first time using it ever so pretty glad I got it to work however very limited on understanding how objects work in unity on the plain

Alastair Aitchison

Hey Amelia, so first of all congratulations on successfully making your first Unity project! Unity defines all objects in an AR scene in metres. Most inbuilt primitives (I.e. a cube, cylinder, sphere, etc.) have a default size of 1x1x1 so, if the scale factor is 1x, that would make them 1metre big in your scene - pretty big! If you wanted to make a 20cm cube, say, go to the Inspector pane (top-right), and set the scale factor to 0.2 in every axis.

Strella Comics (edited)

Comment edits

2026-09-07 18:00 Hello, when I open the application, the screen stays black. What I can do?
2022-09-01 05:09

Daniel-Alexandru Cocolos

Hello Alastair, i have a big issue related to your project. I have followed 100% from all your step from the youtube video but every single time i export the project as apk and move it to my android phone, it is saying that i don't have the right software installed in order to run this apk. Can you provide me more details about issues and how i can fix it?

Curt

Alastair - incredible tutorial as always! I haven't tried this yet, but I'm wondering if this app be used on an unlocked android device that doesn't have a cellular signal or wi-fi? Basically, can I implement this and use it outside without any signal? (sorry if that's a newbie question, but...um...I'm a newbie:))