How to Set up AR Foundation and ARKit in Unity DOTS
Unity Entities 0.50
Last Updated on: 6/24/2022
This will take you about 20 minutes in prep time if you don't have Unity set-up, and 30 minutes in coding and debug time.
Stop struggling with the limited documentation. Follow this step-by-step tutorial: "How to Set up AR Foundation and ARKit in Unity DOTS."
Full workflows and code to set up AR Foundation and ARKit in your DOTS project to create an AR build with DOTS
This gitbook takes you through step-by-step full workflows and code to set up AR Foundation and ARKit in your DOTS project to create an AR build with DOTS. Once you've coded along and fully finished the "How To Set up AR Foundation and ARKit" tutorial, you will be able to set up AR Foundation and ARKit in your DOTS project to create an AR build with DOTS.
High-Level steps to Set up AR Foundation and ARKit:
Install AR Foundation and ARKit packages and AR Foundation-specific subsystems
Set up AR Session and AR Session Origin Game Objects to integrate with AR platforms
Create an iOS build configuration in Assets/BuildSettings then compile code to Xcode
FAQ
What is AR Foundation in Unity DOTS?
Unity's AR Foundation is an API that sits on top of all the hardware AR SDKs. When we ask for "pose" from AR Foundation, AR Foundation automatically translates that request to whatever appropriate implementation. Unity does not implement any of these functionalities itself, it just a translation layer. AR Foundation calls a platform-specific "plug-in" to get the necessary data from the hardware. So adding the "AR Foundation" package is not enough, we must also include specific packages for AR platforms we will be targeting. In our case it will be ARKit. It is important to note that not all AR Foundation functionalities are available for all plug-ins. For example, ARKit and ARCore both now provide access to a depth API. The HoloLens does not provide this data.
How does AR fit into the Technology Stack in Unity DOTS?
Unity has a robust XR plugin framework. Unity has been working to improve their multi-platform offering, enabling direct integrations through a unified plugin framework. The resulting tech stack consists of an API that exposes common functionalities across their supported platforms in a frictionless way for creators while enabling XR hardware and software providers to develop their own Unity plugins. This architecture offers the following benefits: Multi-platform developer tools such as AR Foundation and the XR Interaction Toolkit Faster partner updates from supported plugins via the Unity Package Manager More platforms have access to an interface to leverage Unity’s XR rendering optimizations and developer tools [Source: Unity]
How does Moetsi approach AR in Unity DOTS?
In MainScene we will run a check if we are an AR system. If we are an AR system, we will create an IsARPlayerComponent singleton. We will then use RequireSingletonForUpdate<IsARPlayerComponent> for our AR-specific systems. We will create a new InputSystem for AR, ARInputSystem, that takes in screen taps and translates them to "shoot" commands. We will also update our PlayerCommand to take in AR pose. So our ARInputSystem will be sending "shoot" data through screen taps and updated position through grabbing ARKit's provided "pose". AR Foundation is written using MonoBehaviours. So we will create and update an ARPlayerPoseComponent in an Update(). The MonoBehaviour will use the EntityManager to update our ARPlayerPoseComponent and our ARInputSystem will pull this data to add it to our PlayerCommand.
Haven’t begun learning Unity DOTS yet, and need to start at the very beginning?
If you haven't yet dipped your toes into learning Unity's new multithreaded Data-Oriented Technology Stack (DOTS), now is the time. You can start at the very beginning with Moetsi’s tutorial, which culminates in your very own deployable sample project. You’ll be guided by full workflows, code-alongs, videos, and GIFs along the way.
Whether you have questions about Unity's multithreaded Data-Oriented Technology Stack (DOTS), or about the RaaS API, or even just general questions about data-intensive pipelines for spatial computing applications, come join our Discord! We maintain a friendly channel, and we're always quick to respond.