-
Notifications
You must be signed in to change notification settings - Fork 1
About ARFoundation
ARFoundation is an API developed by Unity Technologies to allow developers to create cross platform AR applications with the Unity Editor. ARFoundation can compile to ARCore on Android, ARKit on iOS, Microsoft HoloLens, and the Magic Leap HMD.
This purpose of this wiki page is to briefly cover the basics of AR Foundation.
Different platforms can have different APIs to build to. For example, on Android, you can build for ARCore, but also Oculus's API, as the Meta Quest HMD runs an android-based OS. And on Windows, there are numerous different AR/VR APIs that Unity can build to.
The XR Plugin Management Package adds a new menu option in the Project Settings that allows us to choose which API ARFoundation will compile for. For Android you should choose ARCore. You shouldn't need to choose anything for iOS as the only apple compatible API as of writing this is ARKit.
If this option doesn't show up, check your Package Manager to see if this package, as well as the ARCore/ARKit/ARFoundation package is installed.
For ARFoundation to work, there must be an AR Session, AR Session Origin, and AR Camera.
The AR Session is what handles all the AR calculations. There isn't much here, it just needs to be present. The way that the AR Session is handled in this project is that it sits in the ARFoundation scene. Since scenes are loaded Additively, they're simply stacked on top of each other. Since the ARFoundation scene is never unloaded, it will always be there to process AR.
The AR Session Origin is a gameobject that acts as the origin to the entire world. There should only be 1 AR Session Origin loaded at any time. If you need to add something to the scene, add it under the AR Session Origin.
The AR Camera is just a regular camera with some extra scripts. If you want the camera background to be passed through and drawn on the display, add an AR Camera Background component to the camera.
You shouldn't need to create all of these yourself. If you have a blank scene open, you can go to GameObject > XR > Convert Main Camera to XR Rig, and it will automatically convert everything for you.
Traditionally, Unity games simulate movement by moving the camera in the direction of the movement. However, ARFoundation prevents you from moving the camera using scripts. The way that you can simulate movement is by moving the rest of the world in the opposite direction. An easy way to do this is by creating a blank GameObject under your AR Session Origin. Then put all your non-camera game objects under this GameObject, then move that around in the opposite direction by subtracting your movement from the transform position of that blank GameObject.
This project uses the Universal Render Pipeline, one of Unity's scriptable render pipelines which is optimized to run on lower power devices. For the camera feed to be rendered by URP, you need to add a component to your URP Renderer. Open your URP Render Asset and click "Add Renderer Feature" and select "AR Background Renderer Feature".