Plant a Tree at Home! My First AR Mobile Mini App with Unity
Follow along to build your own AR App :)
In this mini-project, we’re going to explore building an AR-enabled mobile application with Unity.
The Systems I’m using here are Windows 10 and Android 9. I will also include resources for iOS development in relevant steps.
Tools
a laptop, an AR-enabled mobile phone, and Unity.
Time
approx. 1 hour (setup time included)
Let’s get started!
Step 1: If you haven’t already, download Unity
Unity is a real-time 3D development platform capable of many things ranging from cinematic animation to mobile app development. The version I’m using is 2019.3.12.
If you’ve seen my previous article on my first AR experiment, you’ll know that I switched over from Processing. While Processing also has the necessary tools for AR-enabled mobile development for both Android and iOS environments, Unity provides a real-time visualization to design and visualize your project. Personally, this is easier to understand for my first try at building a mini app.
Wish I’d Known: when installing Unity, make sure to include the relevant modules you’ll need. For my project, I installed the Android Build Support, the iOS Build Support, and the Universal Windows Platform Build Support. You can go to Unity Hub -> Installs to check if you have the icons for the relevant modules.
If you don’t have the right modules, add them by simply expanding the upper-right corner menu for your install, and then to go Add Modules to search and install the right modules.
Step 2: Create and Set Up your Unity Project for Mobile Development
2.1 Create and Launch New Project
Start by launching Unity Hub and select New project. In the pop-up window, select the 3D Template and give your project a name and a location you like.
Wish I’d Known: Pay close attention to the version of Unity your project is created in, especially if you’ve installed multiple versions. When I created this project (and took the screenshot above) I mistakenly launched Unity 2018.4.19. I later realized this when I encountered compatibility issues, and had to quit my current session to re-launch the project in version 2019.3.12.
Launching a new project in Unity could take a while.
2.2 Install the AR Packages
Go to Window -> Package Manager, find and install the relevant packages in the pop-up window. We will need AR Foundation, plus ARCore XR Plugin for Android, or ARKit XR Plugin for iOS.
To set up our project for AR-enabled mobile development, we want to go to Edit -> Project Settings -> Players. Here you will see a tab for each build module you installed.
2.3 Edit Project Settings for Your Relevant System
I’m using the Windows 10 System, so I will not be able to easily develop for iOS environments. If you have iOS systems for both your laptop and your phone, please refer to this amazing YouTube video by The Unity Workbench to set up your project (you can also refer to this when building your project to your phone).
If you’re using a Windows System and developing for an Andriod environment, go to your Android tab in the Edit -> Project Settings -> Players window. In the Other Settings -> Rendering section, find and turn off Multithreaded Rendering. In the Other Settings -> Identification section, find Minimum API Level, and select Android 7.1 ‘Nougat’ (API level 25) from the drop-down menu. These settings are to ensure AR performance.
2.4 Edit the Build Settings
The last setup step before we can design the scene is to edit your settings for deploying your project to the mobile device.
Go back to the main project page and then go to File -> Build Settings. If you’re developing for iOS, please refer back to The Unity Workbench video. If you’re developing for Android, go to the Android tab in the popup window, and then click on the Switch Platform button. It should turn into Build.
Now you’re all set! Let’s go back to the main page and design the scene :)
Step 3: Test Your Scene
3.1 Build a Simple AR Scene
Go to your Hierarchy window and right-click, in the dropdown menu select XR -> AR Session and AR Session Origin.
Select your AR Session Origin object in the Hierarchy window and then in your Inspector window click on the Add Component button to add an AR Plane Manager to your AR Session Origin object.
To understand how the scene will perform, let’s create a cube to start with. Right-click again in your Hierarchy window, and then go to 3D Object -> Cube.
Wish I’d Known: In the Inspector window, you can edit the scale of your object. The default unit 1 means 1 meter in real life.
3.2 Deploy to Your Phone
To test if your scene works, let’s deploy it to your mobile phone. Again, I’m using the Windows 10 System and deploying to an Android 9 device.
If you are also using windows 10, an extra step you need to take here is to find and install the original equipment manufacturers (OEMs) driver for your phone on your laptop. Don’t panic if you’ve never heard of this. Here’s a super helpful guide by Android Developers.
Wish I’d Known: In order to deploy to your Android device, you also need to enable USB debugging on the device. If you don’t know how to, check out this comprehensive article by Android Developers to see where to find it on your device.
When you’re ready, connect your phone to your laptop’s USB port, go back to File -> Build Settings, and then hit the refresh button following Run Device, select your device from the drop-down menu. Click Build and Run.
This could take a while to launch.
You’ll see your project popup on your phone like an app!
Step 4: Let’s Switch the Cube to Something More Fun!
A perk for using Unity is its awesome assets store. You can find assets for almost anything you can think of here, and a lot of them are free!
For this practice project, I’m using the Free Tree assets generously created by Darth_Artisan. Feel free to look around and find your favorite thing to add to your thing, or design your own assets (more on that in an upcoming article)!
After choosing the assets, click on the Open In Unity button from the Unity Assets Store, this will take you back to your Unity project to download and import the assets.
After importing, this assets package will show up in your Assets window.
To add this to your scene, simply find the Prefab file you like and drag it to your Scene window. You can drag the object around in your Scene, or edit using the Inspector window.
When you are happy with the scene design, deploy to your mobile device by repeating Step 3.2!
There you have it! Your own AR App :)
I hope you had fun reading and/or following along. In the next story, we will look into how to build more features and interactions into this App. Stay tuned!
If you are interested in further exploring, here are some resources I found helpful along the way: