
Create an Augmented Reality App With ARKit and Unity
Here, we will learn how to create an Augmented Reality (AR) application using Arkit and Unity.
Before creating an application, you need to set the developing environment.
Developing Environment Setup
Before starting our project, we need the following requirements −
- Unity 2017.1.0 or later
- iOS 11 or later
- XCode 9 beta or later
- iPhone 6S or later, or iPad 2017 or later
Steps to Create an Augmented Reality App
The following are the step-by-step instructions to create an Augmented reality app using ARKit and Unity −
1. Create a New Unity Project
Firstly, to open the project window we need to start Unity and then we need to create a new, empty project.
- Open Unity.
- Click New in the project window.
- Name your project (For ex. ARKitty )
- Press Create project.
We have created our AR project.
2. Access the Asset Store
Use the Asset Store to import essential plugins.
- Open the Asset Store tab in Unity.
- Search for ARKit and find the Unity ARKit Plugin.
- Click Import and confirm the import when prompted.
3. Import Cute Kitten Model
Import a cute 3D kitten model to interact with in your scene.
- Search for Cute Kitten in the Asset Store.
- Import it in the same way you did with the ARKit plugin.
4. Set Up the AR Scene
Add the AR scene and place your kitten model within it −
- Navigate to Assets > Examples, and find UnityARKitScene.
- Drag UnityARKitScene into the Hierarchy.
- Locate the kitten model under Assets and drag it to Hierarchy > HitCubeParent.
5. Clean Up the Scene
Remove unnecessary objects and adjust settings for better performance.
- Right-click and delete HitCube and RandomCube from the scene.
- Select GeneratePlanes and ARKitControl in the Inspector and uncheck the Tag.
6. Adjust Camera Settings
Set the camera settings for a better AR experience.
- Select Main Camera under CameraParent in Hierarchy.
- Set Near in the Inspector to 0.01.
7. Add Hit Test Script
Add a script that enables users to tap the screen and interact with the kitten model.
- Select the kitten in the Hierarchy.
- Find UnityARHitTestExample.cs in UnityARKitPlugin > Plugins > Helpers.
- Drag this script onto the kitten in the Inspector.
- Assign the kitten to the Hit transform field in the script.
8. Save Your Scene
Save your progress by naming your scene.
- Go to File > Save Scene, and name it ARKittyTest.
Building the App
Now that your AR scene is set up, it's time to configure the necessary settings and compile your project into an iOS app for deployment.
Continue these steps to ensure everything is properly configured and ready to go −
9. Configure Build Settings
Configure the build settings for iOS to prepare the project for deployment.
- Go to File > Build Settings.
- Select iOS as the platform.
- Click Player Settings, find Bundle Identifier, and enter something like com.yourname.arkittytest.
10. Build the Project
Compiling the project into an iOS app
- Click Build and save it as ARKittyTest.
11. Open in XCode
Open your Unity project in Xcode for final adjustments and to prepare it for deployment on your iOS device.
- Locate the Unity-iPhone.xcodeproj file in Finder and open it in XCode.
- In XCode, select Unity-iPhone and set the Bundle Identifier to match what you entered in Unity.
- Choose your development team under Signing.
12. Build and Run
Connect your iOS device and run the app
- Connect your iOS device.
- Select it as the target in XCode.
- Click the Build and Run button.
The kitten is live! We have successfully created our first AR app using Apple ARKit and Unity. In the future, we will explore more advanced features, such as ARKit face tracking, ARKit object detection, and ARKit motion capture.