Insight

How to optimize your Augmented Reality app and minimize AR Drift

Female with long brown hair is standing smiling in front of a metal wall with a hand on one hip
Rosemary Reilman Technology Lead

Overview

Back in March of 2020, Erika Looney, our visual design lead, wrote about some of the challenges that Interactive Knowledge faced in conceptualizing a location-based Augmented Reality app. At that time, now over a year ago we were in the very early stages of the project. Since then we have released a few different iterations of the Gettysburg AR Experience on both the App Store and Google Play Stores and our team has gained vast experience in  augmented reality and game development.

What’s “under the hood”?

We chose to build the app on Unity, because the 3D models and characters were all being developed using Unity, and our team already had some experience with the software. We also chose to utilize Unity’s AR Foundation Framework. There are a few other amazing AR development tools out there but AR Foundation allowed our AR Experience to tap into core features of both iOS and Android OS without additional cost.

 

What we’ve learned

About AR Drift

If you’ve been developing at all in the AR space, you probably have some experience with AR drift. This is when you are viewing an AR Object with your device’s camera and the object appears to be floating away from you as you move throughout your real world space. Below you’ll find some techniques we used to vastly reduce AR drifting within scenes.

Make sure you’re on the most updated version of your software. 

AR is still a relatively new software and concept. Things are changing all the time. Sometimes a simple update to your software or Unity Packages can make a big difference. For example, in the few months we have been working on this project there has been the addition of AR Occlusion. The occlusion feature adjusts the AR scene to recognize and account for environment obstacles (i.e. trees, buildings and people) when rendering scene elements, which we have found greatly improved drifting. However, support for occlusion is currently limited to the most recent OS versions of Apple and Android devices. 

Double check your device support.

Is your device on the latest version of it’s OS? For Android devices, is your ARCore app up-to-date? Is your device listed as supported for the features you’re using? Android ARCore support and iOS ARKit device support.

Scene and Project Optimization

Our AR scenes are very large so we had to work hard to optimize the scenes as best we could. For example, one of the most compelling scenes in our AR app is a recreation of President Abraham Lincoln delivering the Gettysburg Address. This very large scene, which includes the crowd watching the speech, from end to end, is approximately 100 meters which presented some challenges. Some tips for optimizing scenes in Unity include: 

Use a Tweening library to handle UI animations

Tweening allows a more performant way to do animations. You could use Animators for UI elements but it will require updating them every frame. Instead use a Tweening library or your own code to handle UI animations. We likeLeanTween.

Utilize Static Batching and Light Baking when possible. 

When using light baking and static batching, Unity can batch these objects together and in turn cut down on how many times Unity has to “redraw” objects on the screen. Read more about draw call batching, and step-by-step instructions on setting up light baking and static batching

Cache Components and reduce object searches.

This is specific to Unity, when using GetComponent and GameObject.Find methods frequently it can take a toll on performance. Instead of using GameObject.Find, set up the reference or variable in Inspector to use in your script. To cache Components, use a variable to save it for reuse throughout the script. For example:

// Save Component to variable to reuse later
Text myText = gameObject.GetComponent<Text>();
myText.text = “Update Text”;
myText.text = “Update Text Again”

// Calling GetComponent multiple times during runtime can have performance downsides.
gameObject.GetComponent<Text>().text = “Update Text”;
gameObject.GetComponent<Text>().text = “Update Text Again”

 

For more helpful reading check out: 

 

You can read more about the Gettysburg AR Experience app in our case study.