Unity has streamlined AR foundation so that you can write your AR app’s code once and build it for both Android and IOS. In this tutorial we will learn
- How to set up your project for AR.
- Common mistakes to avoid
- Simple plane detection.
I am using Unity 2021.3.1 for this tutorial. If you are using an older verson then some setup steps may vary.
Starting a New AR project
You can use the Unity AR template or just start a simple 3D project. I would suggest creating a empty 3D project. If you create a new project with AR template then you will have to remove the sample project before building your own APP.
Setting up Android and IOS build requirement
If you have not already done it you will have to setup your Unity editor to build for Android or IOS based on your target platform before proceeding.
Go to Unity hub>Installs>click on the gear icon and select add modules.
Select Android Build support and IOS build support and install them.
After the installation is complete. Go to the projects tab in Unity hub.
Click New Project and create a new 3D project.
Setting up AR foundation
The next step is to install AR foundation. You can skip this if you have used the AR template while creating your new project.
Go to Windows>Package Manager.\
Search for AR foundation and install it.
Go to Edit>Project Settings>XR plug-in Management.
Select the Android or IOS tab based on your platform.
Check the plugin Arcore for Android and Arkit for IOS.
Features available in AR foundation
Arcore and ARkit are two different plugins with some common features. Some features may be available based on the platform. You can use the image below for reference.
You need to change the following settings based on your target platform
Go to Edit>Project settings>Player settings> Other settings
- Remove Vulkan API from Graphic Api settings.
- Set the minimum API level to 24.
- Set the scripting backend to IL2CPP
- Check requires ARkit support.
- Set target minimum IOS version to 11.0.
- Select architecture as ARM64.
Basic Plane Detection in AR
Let’s set up our scene to detect planes.
Open a new scene.
Delete the Main camera from your scene.
Add AR Session and AR Session Origin to your scene by right clicking on the hierarchy window>XR
Your AR Session Origin includes your AR camera so it should always be kept at (0,0,0).
Add an AR default plane to your scene. Create a prefab from the AR plane and delete it from the Hierarchy.
Click on AR Session Origin and go to the inspector window.
Click on Add Component and add AR Plane manager.
Drag on drop your AR plane prefab to the plane prefab variable on the AR plane manager.
Set the Detection mode to Everything.
You are ready to test your first AR APP.
Build and run your scene on your phone. Your phone should detect the planes.