How to Use ARKit and Unity to Create 6DOF Mobile VR
Recently I had the not so original idea of using tracking enabled Apple’s ARKit in order to create a 6DOF mobile VR experience. After some research partnered with a healthy dose of trial and error, I was able to develop a method that allowed me to do this using Unity. While there are still problems with it, mainly that the experience is somewhat laggy with bugging tracking, I wanted to share the procedure in the hopes that others could replicate it and improve upon it. I personally think that the ability to walk around in mobile VR will help people to create more immersive experiences that will more accessible to the general public thanks to initiatives like Google Cardboard. Hopefully, if you can get this to work you can end up with something like this.
There is no code involved in this, just the correct environment and tools.
1. Set-Up
This is what I used in order to create this demo, but there is a chance that other versions of Unity or Xcode could still be used to make this work. It is also important to note that this tutorial assumes that you already have a Unity environment that works with iOS. If not, refer to this tutorial in order to get the environment ready.
- Unity 2018.2.21f1
- Xcode 10 or greater
- iPhone running iOS 12.0 or later
- Compatible Google Cardboard Viewer
2. Preparing the Unity Environment
- Create a 3D Unity Project through the Unity Hub.
- Change Platform to iOS in File > Build Settings using the switch platform button on the left once iOS is selected
- Then hit the Player Settings button beside the Switch Platform button.
- In the Other Settings section, check “Requires ARKit Support”
- Change the target minimum iOS version to 12.0
- Change the Architecture to ARM64
- Add a Bundle Identifier in the Other Settings section. This is going to be something like com.CompanyName.ProductName; change it to something unique.
3. Installing Packages
- Go to Window > Package Manager
- Click “All” then install AR Foundation and ARKit XR Plugin
- Then go to the GVR page and download the GVR SDK for Unity
- Install the SDK into the Unity Project using the file in the unzipped folder
If Unity requests an API update during the install allow it
4. Setting the Scene
Delete the Main Camera
Right-click in the scene hierarchy, go down to XR on the menu, then click on AR Session to add it to the scene
Inside the Project Hierarchy go to Assets > Google VR > Prefabs and drag the GvrMain Prefab into the project
Disable tracking on the head component in GvrMain > Head within the scene hierarchy
With GvrMain selected, click add component and select (this may need to be searched) the tracked pose driver from the XR folder
Switch the pose source on the tracked pose driver to the color camera
Create a cube
Then on the cube change the position Z to 1 and change the X, Y, Z of scale to 0.1
5. Finishing Up
Finally, save the scene, then build it with either ⌘B or going to File > Build and Run (if asked to strip ARKit allow it). Make sure that the iPhone is plugged into the computer in order to install the app. Once the app is running, slide the phone into the Google Cardboard viewers and if all goes well it should look like the demo above. Just note that the cube will spawn 0.1 meters in front of where ever the phone opens the app. Hopefully, this was useful, so go forth and create new 6DOF experiences.