--- uid: arfoundation-manual --- # About AR Foundation AR Foundation allows you to work with augmented reality platforms in a multi-platform way within Unity. This package presents an interface for Unity developers to use, but doesn't implement any AR features itself. To use AR Foundation on a target device, you also need separate packages for the target platforms officially supported by Unity: * [ARCore XR Plug-in](https://docs.unity3d.com/Packages/com.unity.xr.arcore@4.2/manual/index.html) on Android * [ARKit XR Plug-in](https://docs.unity3d.com/Packages/com.unity.xr.arkit@4.2/manual/index.html) on iOS * [Magic Leap XR Plug-in](https://docs.unity3d.com/Packages/com.unity.xr.magicleap@6.0/manual/index.html) on Magic Leap * [Windows XR Plug-in](https://docs.unity3d.com/Packages/com.unity.xr.windowsmr@4.0/manual/index.html) on HoloLens AR Foundation is a set of `MonoBehaviour`s and APIs for dealing with devices that support the following concepts: - Device tracking: track the device's position and orientation in physical space. - Plane detection: detect horizontal and vertical surfaces. - Point clouds, also known as feature points. - Anchor: an arbitrary position and orientation that the device tracks. - Light estimation: estimates for average color temperature and brightness in physical space. - Environment probe: a means for generating a cube map to represent a particular area of the physical environment. - Face tracking: detect and track human faces. - 2D image tracking: detect and track 2D images. - 3D object tracking: detect 3D objects. - Meshing: generate triangle meshes that correspond to the physical space. - Body tracking: 2D and 3D representations of humans recognized in physical space. - Colaborative participants: track the position and orientation of other devices in a shared AR experience. - Human segmentation: determines a stencil texture and depth map of humans detected in the camera image. - Raycast: queries physical surroundings for detected planes and feature points. - Pass-through video: optimized rendering of mobile camera image onto touch screen as the background for AR content. - Session management: manipulation of the platform-level configuration automatically when AR Features are enable or disabled. - Occlusion: allows for occlusion of virtual content by detected environmental depth (environment occlusion) or by detected human depth (human occlusion). ## Platform Support AR Foundation does not implement any AR features itself but, instead, defines a multi-platform API that allows you to work with functionality common to multiple platforms. ### Feature Support Per Platform You can refer to this table to understand which parts of AR Foundation are relevant on specific platforms: | |ARCore|ARKit|Magic Leap|HoloLens| |--------------------------------|:----:|:---:|:--------:|:------:| |Device tracking | ✓ | ✓ | ✓ | ✓ | |Plane tracking | ✓ | ✓ | ✓ | | |Point clouds | ✓ | ✓ | | | |Anchors | ✓ | ✓ | ✓ | ✓ | |Light estimation | ✓ | ✓ | | | |Environment probes | ✓ | ✓ | | | |Face tracking | ✓ | ✓ | | | |2D Image tracking | ✓ | ✓ | ✓ | | |3D Object tracking | | ✓ | | | |Meshing | | ✓ | ✓ | ✓ | |2D & 3D body tracking | | ✓ | | | |Collaborative participants | | ✓ | | | |Human segmentation | | ✓ | | | |Raycast | ✓ | ✓ | ✓ | | |Pass-through video | ✓ | ✓ | | | |Session management | ✓ | ✓ | ✓ | ✓ | |Occlusion | ✓ | ✓ | | | **Note:** To use ARCore cloud anchors, download and install Google's [ARCore Extensions for Unity's AR Foundation](https://developers.google.com/ar/develop/unity-arf). ### Supported Platform Packages The following platform packages and later implement the AR Foundation features indicated above: |Package Name |Version | |:--- |:--- | |ARCore XR Plug-in | 4.2 | |ARKit XR Plug-in | 4.2 | |ARKit Face Tracking | 4.2 | |Magic Leap XR Plug-in | 6.0 | |Windows XR Plug-in | 5.0 | ## Subsystems AR Foundation is built on subsystems. A **subsystem** is a platform-agnostic interface for surfacing different types of information. The AR-related subsystems are defined in the [`AR Subsystems`](https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@4.2/index.html) package and use the namespace `UnityEngine.XR.ARSubsystems`. You occasionally need to interact with the types in the AR Subsystems package. Each subsystem handles specific functionality. For example, `XRPlaneSubsystem` provides the plane detection interface. ### Providers A **provider** is a concrete implementation of a subsystem. For example, the `ARCore XR Plugin` package contains the ARCore implementation for many of the AR subsystems. Because different providers have varying support for specific features, each subsystem also has a descriptor that indicates which specific subsystem features it supports. For example, the `XRPlaneSubsystemDescriptor` contains properties indicating whether it supports horizontal or vertical plane detection. Each individual provider determines how to implement each subsystem. In general, they wrap that platform's native SDK (for example, ARKit on iOS and ARCore on Android). # Installing AR Foundation To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest/index.html). Subsystems are implemented in other packages. To use AR Foundation, you must also install at least one of these platform-specific AR packages from the Package Manager window (menu: **Window** > **Package Manager**): - ARKit XR Plug-in - ARCore XR Plug-in - Magic Leap XR Plug-in - Windows XR Plug-in # Glossary | **Term** | **Description** | |-|-| | **Tracking** | The AR device's ability to determine its relative position and orientation in the physical world. If the environment is too dark, for example, the device might "lose tracking", which means it can no longer accurately report its position. | | **Trackable** | A real-world feature, such as a planar surface, that the AR device tracks and/or detects. | | **Feature Point** | A specific point in a point cloud. An AR device uses the device’s camera and image analysis to track specific points in the world, and uses these points to build a map of its environment. These are usually high-frequency elements, such as a knot in a wood-grain surface.| | **Session** | An AR instance. | | **Session Space** | The coordinate system relative to the beginning of the AR session. For example, session space (0, 0, 0) refers to the position at which the AR session was created. An AR device typically reports trackables and tracking information relative to its session origin.| # Using AR Foundation ## Samples For examples, see the [ARFoundation Samples](https://github.com/Unity-Technologies/arfoundation-samples) GitHub repository. ## Provider plug-in setup Provider plug-ins must be enabled before AR Foundation can use them. You can enable specific plug-in providers for each target platform from the [XR Plug-in Management](https://docs.unity3d.com/2020.2/Documentation/Manual/configuring-project-for-xr.html) window.  ## Scene setup A basic AR scene hierarchy looks like this:  To create these scenes automatically, right-click in the scene Hierarchy window, and select **XR** > **AR Session** or **XR** > **AR Session Origin** from the context menu.  The required components are explained in more detail below. ### ARSession An AR scene should include an `ARSession` component. The AR Session controls the lifecycle of an AR experience by enabling or disabling AR on the target platform. The `ARSession` can be on any `GameObject`.  When you disable the `ARSession`, the system no longer tracks features in its environment, but if you enable it at a later time, the system attempts to recover and maintain previously-detected features. If you enable the **Attempt Update** option, the device tries to install AR software if possible. Support for this feature is platform-dependent. > [!NOTE] > An AR session is a global construct. An `ARSession` component manages this global session, so multiple `ARSession` components will all try to manage the same global session. #### Checking for device support Some platforms might support a limited subset of devices. On these platforms, your application needs to be able to detect support for AR Foundation so it can provide an alternative experience when AR is not supported. The `ARSession` component has a static coroutine that you can use to determine whether AR is supported at runtime: ```csharp public class MyComponent { [SerializeField] ARSession m_Session; IEnumerator Start() { if ((ARSession.state == ARSessionState.None) || (ARSession.state == ARSessionState.CheckingAvailability)) { yield return ARSession.CheckAvailability(); } if (ARSession.state == ARSessionState.Unsupported) { // Start some fallback experience for unsupported devices } else { // Start the AR session m_Session.enabled = true; } } } ``` #### Session state To determine the current state of the session (for example, whether the device is supported, if AR software is being installed, and whether the session is working), use `ARSession.state`. You can also subscribe to an event when the session state changes: `ARSession.stateChanged`. |`ARSessionState`|**Description**| |-|-| |`None`|The AR System has not been initialized and availability is unknown.| |`Unsupported`|The current device doesn't support AR.| |`CheckingAvailability`|The system is checking the availability of AR on the current device.| |`NeedsInstall`|The current device supports AR, but AR support requires additional software to be installed.| |`Installing`|AR software is being installed.| |`Ready`|AR is supported and ready.| |`SessionInitialized`|An AR session is initializing (that is, starting up). This usually means AR is working, but hasn't gathered enough information about the environment.| |`SessionTracking`|An AR session is running and is tracking (that is, the device is able to determine its position and orientation in the world).| ### AR Session Origin  The purpose of the `ARSessionOrigin` is to transform trackable features, such as planar surfaces and feature points, into their final position, orientation, and scale in the Unity scene. Because AR devices provide their data in "session space", which is an unscaled space relative to the beginning of the AR session, the `ARSessionOrigin` performs the appropriate transformation into Unity space. This concept is similar to the difference between "model" or "local" space and world space when working with other Assets in Unity. For instance, if you import a house asset from a DCC tool, the door's position is relative to the modeler's origin. This is commonly called "model space" or "local space". When Unity instantiates it, it also has a world space that's relative to Unity's origin. Likewise, trackables that an AR device produces, such as planes, are provided in "session space", relative to the device's coordinate system. When instantiated in Unity as `GameObject`s, they also have a world space. In order to instantiate them in the correct place, AR Foundation needs to know where the session origin should be in the Unity scene. `ARSessionOrigin` also allows you to scale virtual content and apply an offset to the AR Camera. If you're scaling or offsetting the `ARSessionOrigin`, then its AR Camera should be a child of the `ARSessionOrigin`. Because the AR Camera is session-driven, this setup allows the AR Camera and detected trackables to move together. #### Scale To apply scale to the `ARSessionOrigin`, set its `transform`'s scale. This has the effect of scaling all the data coming from the device, including the AR Camera's position and any detected trackables. Larger values make AR content appear smaller. For example, a scale of 10 would make your content appear 10 times smaller, while 0.1 would make your content appear 10 times larger. ### AR Pose Driver The `AR Pose Driver` drives the local position and orientation of the parent GameObject according to the device's tracking information. The most common use case for this would be attaching the `ARPoseDriver` to the AR Camera to drive the camera's position and orientation in an AR scene.  #### Legacy Input Helpers and the Tracked Pose Driver component The `ARPoseDriver` provides a similar functionality to the `TrackedPoseDriver` from the `com.unity.xr.legacyinputhelpers` package and was implemented to remove the dependency on that package. Projects are able to use either the `ARPoseDriver` component or the `TrackedPoseDriver` component to drive a GameObjects transform. It is not recommended to use both as the behaviour is undefined. `Use Relative Transform` option is unavailable for the `ARPoseDriver` because it introduces additional unnecessary transformations.  ### AR Camera manager The `ARCameraManager` enables features for the AR Camera, including the management of the device camera textures and the properties that set the light estimation modes.  | **Setting** | **Function** | |-|-| | **Auto Focus** | Enables or disables the hardware camera's automatic focus mode. When disabled, the focus is fixed and doesn't change automatically. _Note:_ Availability of *Auto Focus* depends on camera hardware so this preference might be ignored at runtime. | | **Light Estimation** | Estimates lighting properties of the environment. There are five options: