Developing an Augmented Reality Hello World App with zero coding in Unity using ARFoundation and…
4 min read
In this article we are going to create a simple Augmented Reality Experience where you can place a cube on any plane surface. This serves as a perfect Hello World Example to get started with Augmented Reality. We are gonna be using Unity and a bunch of packages to do so. There is absolutely zero coding involved in this Hello World Example.
Before diving into the practical steps, let’s understand a few things first. A lot of the steps that you see ahead will seem like “magic”. It’s as if you are just following instructions, blindly. You won’t understand the underlying concepts and that’s totally fine. Get it working first. Then we can jump into the “Why” aspect of each step involved.
So what are we developing here? Let’s take a look. Here I have my phone and I will launch my app. Once I open my app you see that my phone’s camera starts capturing my room. This is the user’s environment.
As I move the phone around slowly and scan my room, it starts tracking the plane surfaces in my room. This is being done through Environmental Understanding and Plane Detection.
What is Environmental Understanding?
Environmental Understanding refers to understanding the real world environment by detecting feature points and planes and using them as reference points to map the environment. Also referred to as context awareness.
What is Plane Detection?
Plane Detection refers to the process by which horizontal and vertical surfaces are detected in your environment. These surfaces can be used to place and orient digital objects.
In our case when we tap on a detected plane surface, a cube gets placed. We cannot orient it yet but don’t worry. I will show you how easy it is to do that in the next tutorial. For now, this is what we are going to develop.
Let’s see how.
The first step is to open Unity and create a new 3D Project. Name it whatever you want to.
Download the following 4 packages —
ARCore XR Plugin / ARKit XR Plugin
Be cautious about the versions.
In the hierarchy window, remove the MainCamera. Right click and bring in the following GameObjects -
ARPlacementInteractable (You will see that InteractionManager also gets added. That’s fine. Ignore it for now)
Add the following components to the ARSessionOrigin Game Object —
AR Raycast Manager
AR Plane Manager
Add the MainCamera tag to the ARCamera Game Object
Add the following components to the ARCamera Game Object —
Make a prefab of the Cube GameObject and then remove it from the scene.
Select ARPlacementInteractable. Drag and drop the cube prefab in the PlacementPrefab field of the ARPlacementInteractable Script component in the ARPlacementInteractable GameObject.
Make a prefab of the AR Default Plane GameObject and then remove it from the scene.
Select ARSessionOrigin. Drag and drop the AR Default Plane Prefab in the PlanePrefab field of the AR Plane Manager Script component in the AR Session Origin GameObject.
Build for Android
Go to File > Build Settings > Select Android > Switch Platform. Let the switching process complete. Now click on Player Settings.
In the Player Settings window go to XR Plugin Management > Check ARCore.
Go back to the Build Settings window. Connect your testing device via USB. Click on the refresh button beside “Run Device” drop down menu. Select your device from the drop down menu and then Build and Run. When a window pops up create a new folder called “Builds”, double click it to open it, give a name for your apk and then click save. Basically all the files related to the build will be pushed inside this Builds folder now, including the APK.
The app should start running on your phone now. Move your phone around pointing the camera towards a plane surface. Planes will start getting highlighted. These are the tracked planes. Now tap on a highlighted plane and you will see a cube appear. Congrats.
Follow me on LinkedIn or Twitter for more updates related to AR/VR
Did you find this article valuable?
Support Rajat Kumar Gupta by becoming a sponsor. Any amount is appreciated!