--- robots: noindex, nofollow --- # Setting up AR Foundation in Unity [toc] We willl focus on Android and ARCore , but except from a few basic project settings, AR Foundation is cross-platform by nature. ARKit currently supports a lot more AR features than ARCore. Check out the [Feature Support by Platform](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/index.html) matrix in the docs. ![](https://hackmd.io/_uploads/r13nEXXzs.png) ## Requirements 1. An installation of a stable Unity Engine on Windows or MAC 1. An AR supported Android. ## Let’s Get Started :::success First, create a new 3D project according to [Google’s AR Foundation guidelines](https://developers.google.com/ar/develop/unity-arf/quickstart#configure_player_settings). ::: :::info We need to add the `Android Build Support` into the Unity Hub modules for the `2020` Unity version. *You do not need Visual Studio 2019 Community edition, so just skip that* ::: The “Configure Player Settings” section is relevant. Quick summary: * Step 1: Open up the File > Build Settings * Select Android * Press "Switch platform" (If your phone is connected and allows usb debugging, then it should appear in "Run Devices") * Step 2: Go to "Edit > Project settings" and click on Player Settings then search for the `Other Settings` section * Disable Multithreaded Rendering as ARCore doesn't support it yet. * Keep Auto Graphics API enabled but remove the Vulkan Graphics API as ARCore doesn't support it yet. * Set the minimum API level to be 24, as its the minimum API level required by ARcore. * *Also, it's a good practice to fill in some information about your project so you can find it in your apps on your phone, between all the other clutter you have installed on there!* :::warning **64-bit Requirement?** > All new apps published in the Play Store need to support 64-bit architectures. This also [applies to ARCore](https://developers.google.com/ar/64bit). However, the **Mono scripting** backend in Unity can only compile 32-bit apps. >Therefore, Google recommends switching to the **IL2CPP** scripting backend to enable the ARM64 architecture (in addition to ARMv7 for 32-bit). Enable ARM64 if your phone is 64-bit ::: ![](https://hackmd.io/_uploads/H1btv77fj.png) ## XR Plug-in Management Go to *Project Settings* *> XR Plug-in Management*. Click on "Install". This uses the Unity Package Manager to install the **XR Plugin Management** plug-in. ![](https://hackmd.io/_uploads/rJVjFX7fi.png) Then, enable *ARCore*. This installs the ARCore XR Plugin, as the provider plugin. ![](https://hackmd.io/_uploads/H1thFXXfs.png) Finally, we would recommend going to the Unity Package Manager and to update all Plug-ins. The auto-installed versions don’t necessarily have to be the latest. ![](https://hackmd.io/_uploads/B1i39mQfi.png) By default, in the ARCore settings, also Depth measurement support is set to "required". Most current ARCore capable devices do not have this yet. You can always check the current smartphone list in [ARCore Supported Devices](https://developers.google.com/ar/devices), which also lists Depth API support. So, in case your use-case doesn’t rely on depth estimation, you should make depth "optional". ![](https://hackmd.io/_uploads/BJP_cXQzo.png) If the XR Plug-in Management didn’t install the *AR Foundation plug-in* automatically, you must do so yourself. In the Package Manager, switch to “Packages: Unity Registry” to see all available packages instead of just the installed packages. Then, install the latest version of the *AR Foundation plug-in*: ![](https://hackmd.io/_uploads/rkC25mXGj.png) With XR plugin enabled, go to "File > Build and Run"... :::danger **ERRORS** ![](https://hackmd.io/_uploads/rkUb14Xfs.png) **Resolve the errors** Make sure that in "Edit > Project Settings > Player" * Auto Graphics API is selected ![](https://hackmd.io/_uploads/HyfVk4Qfo.png) * The minimum level of android is Nougat 7.0 ! * Make sure ARM64 is enabled![](https://hackmd.io/_uploads/BJS_J47Go.png) ::: ## AR Scene Setup First, remove the default camera in your scene. Then, add `AR Session` and `AR Session Origin` through the context-menu of the scene. ![](https://hackmd.io/_uploads/rk-hi7mfj.png) In case you don’t see these menu options, install the “AR Foundation” plug-in as seen in the previous section, and ensure that Android (or iOS) is the active target platform. ## Main AR Foundation Components AR Foundation uses some fundamental concepts which are part of every AR app. The following sections briefly explain what they do, as you will need to interact with some of these GameObjects or configure the settings to suit your application scenario. ### AR Session This GameObject controls the lifecycle of your AR experience. It checks for AR device support. It manages the current state of the session – when everything is initialized and OK, the state will be `SessionTracking`. The GameObject also provides means to enable and disable AR, e.g., when you’re in a menu. ![](https://hackmd.io/_uploads/rywaJV7zs.png) `AR Session` is a global construct, you only have it one time in the scene, attached to any component. The *Attempt Update* setting tries to install AR libraries on the device if possible – e.g., the ARCore services through the Google Play Store. The GameObject also contains the `AR Input Manager` script. It’s also required 1x anywhere in the scene and enables world tracking. ### AR Session Origin The second GameObject we just added is the `ARSessionOrigin`. It applies transformations (position, orientation, and scale) from trackable features (like feature points or planes) to anchored objects in the Unity scene’s. Trackables in AR are managed in “session space” by the device. They are relative to the device’s coordinate system. However, your GameObjects in Unity are managed in world space. ![](https://hackmd.io/_uploads/SysQxVXMj.png) To make sure the virtual camera moves along with the real smartphone’s camera through the world, `AR Camera` should be a child of `AR Session Origin`. ![](https://hackmd.io/_uploads/H1Z7gVQfo.png)