# Adding AR Capabilities

Now that you are successfully able to stream 3D content into Unity and know how to make custom adjustments, it's time to add AR capabilities to your project.

Unity provides a framework purpose-built for AR development called [AR Foundation](https://unity.com/unity/features/arfoundation). It allows you to build across multiple mobile and wearable AR devices, such as Android with ARCore and iOS with ARKit.

Before using AR Foundation, make sure that your iOS device is compatible with [ARKit](https://developer.apple.com/augmented-reality/arkit/) or that your Android device has [ARCore](https://developers.google.com/ar/discover/supported-devices) or [Google Play Services for AR](https://play.google.com/store/apps/details?id=com.google.ar.core\&hl=en_US) installed.

### 1. Installing AR Foundation

Clone the open-source [Unity + AR Foundation + echo3D](https://github.com/echo3Dco/Unity-ARFoundation-echo3D-example) example project on GitHub and open it in Unity.

### 2. Setup a Simple AR Application

Open the AR Foundation sample scene located in:

`Assets > AR Foundation > Scenes > SimpleAR > SimpleAR`

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XXDckndNUXAAqpyIM%2F1.jpg?alt=media\&token=a651c060-24c6-4c6d-99e9-c7c236defe48)

In the hierarchy click on the `AR Session Origin` game object.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XXlYWuPv6zQRcEJSq%2F2.jpg?alt=media\&token=ebbddeb3-81f8-4cd0-ba52-39c354c0fdc7)

In the inspector view, look for the `Place on Plane` script and set the `Placed Prefab` to the echo3D prefab in the `Assets > echo3D` folder.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XZfe4zkAo8SiK1pL9%2F3.jpg?alt=media\&token=a82e709d-fe26-4ea7-830d-352bd3b2ebaa)

### 3. Set your API Key

Edit the echo3D prefab and set your API key through in the Inspector view.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6Xj7huqcl5sxLat8YW%2F7.JPG?alt=media\&token=ac74e559-4eaf-46a0-a571-01f6ab0ecd75)

#### Do you want to test the app in Unity before building it?

You can test the connection to echo3D by pressing `Play` to start the app on Unity.&#x20;

Note that the `Game` view will show a black screen - that is expected as the `Game` view tries to access the mobile AR camera which doesn't exists when running on a desktop machine.

Switch to the `Scene` view and drag the echo3D prefab from`Assets > echo3D` into the hierarchy.

If the API key was set correctly you should be able to see 3D assets from the echo3D platform stream into Unity.

Stopping Unity from playing should reset everything.

You are now ready to build the AR app on a mobile device.

### 4. Build and Run the 3D/AR/VR or Spatial Computing Application

Connect your [ARKit](https://developer.apple.com/augmented-reality/arkit/)/[ARCore](https://developers.google.com/ar/discover/supported-devices)-compatible mobile device or AR/VR/Spatial Computing headset to your desktop machine using a USB cable.

Go to `File > Build Settings...` or press `Ctrl+Shift+B`.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XfVEQ3Yd01-4XtdYs%2F4.jpg?alt=media\&token=c8ec734a-d19c-4b8a-88f3-960449834d10)

Make sure to set your platform to (either Android, iOS, or Universal Windows Platform (UWP), etc.) by choosing the target platform and pressing the`Switch Platform` button on the bottom right corner.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6Xh5JLfVF9_Oo9B1zm%2F5.jpg?alt=media\&token=8bb13a4b-07ac-4755-86f4-ae3f676458e6)

Verify that the `SimpleAR` scene is ticked in the `Scenes in Build` list and click `Build And Run`.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XhKMwamUcG2LCwB4a%2F6.jpg?alt=media\&token=fc27c14b-c666-4358-974c-45dbb535d307)

### 5. Use your AR Application

First, [add a 3D model](https://docs.echo3d.com/quickstart/add-a-3d-model) to the platform.

When the application is loaded on your mobile device you might be asked to approve camera access permission.

Move the phone around until a surface is detected.

Tap the screen to place the model on the surface.

The model will steam and render in front of you.

![](https://3757500311-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M41BcmqhdFQ3r89wcIR%2F-M6XGdldX1DOwh7YUY-7%2F-M6XoDXCtBba3Y2fTuvX%2F8%20\(Compressed%2035\).gif?alt=media\&token=61182957-4f62-4072-89c7-7fef785cab57)

{% hint style="info" %}
If the model is too big or too small, go back to the platform and [add metadata](https://docs.echo3d.com/web-console/manage-pages/data-page/how-to-add-data#adding-metadata) to affect its scale. After adding metadata the model should change automatically.&#x20;
{% endhint %}

**You did it! 🎉**
