Quickstart for Cloud Anchors in Unity for Android

Use cloud anchors to build AR experiences that Android and iOS users can share.

Prerequisites

  • If you are new to working with anchors, see Working with Anchors for an introduction.

  • The following steps assume that you have already installed and configured the ARCore SDK for Unity to target Android.

    If not, see the ARCore SDK Quickstart for Android for installation and environment configuration instructions.

Requirements

See Requirements in the Quickstart for Android.

Use Cloud Anchors

Set up your development environment for working with cloud anchors and try out the sample app.

About cloud anchor ID sharing

Apps with cloud anchor capabilities need a way to share cloud anchor IDs between devices.

The CloudAnchor sample app uses Unity's Networking feature for sharing cloud anchor IDs between devices on the same network. You can use a different solution in your own apps.

Add an API Key

To use the ARCore Cloud Anchors API in your app, you'll need an API Key.

  1. Obtain an API Key. See Setting up API keys in the Google Cloud Platform Console Help Center if you are new to working with API keys.

  2. Enable the ARCore Cloud Anchor API for your Google Cloud Platform project.

  3. Add your API key to your project:

    • In Unity, go to Edit > Project Settings > ARCore
    • Add your API key to the Cloud Services API Key field.

Open the sample

The CloudAnchor sample is included with the ARCore SDK for Unity.

  1. In the Unity Project window, you can find the CloudAnchor.unity scene in:
    Assets > GoogleARCore > Examples > CloudAnchor > Scenes

Try out the sample

Build and run the CloudAnchor sample app to try out hosting and resolving cloud anchors.

  1. Make sure that your build and player settings are configured as described in Configure build settings steps in the ARCore SDK Quickstart for Unity.

  2. Make sure that developer options and debugging are enabled on your phone.

  3. Connect your phone to your development machine via USB.

  4. Click Play in Unity.

  5. The sample app launches on your phone using Instant Preview.

  6. Move your phone around until ARCore starts detecting and visualizing planes.

  7. Tap a plane to anchor an Andy Android object on it.

  8. Tap the HOST button to host the anchor.

    A host request is sent to the Google Cloud Anchor service. The host request includes data representing the anchor's position relative to the visual features near it. A successful host request establishes a cloud anchor here and assigns it a cloud anchor ID.

    The app displays a room code after the hosting request succeeds. You can use the code to access previously hosted cloud anchors for this room, using the same device or another device.

  9. Tap RESOLVE and enter a previously returned room code to access hosted cloud anchors for this room.

    A resolve request is sent to the Google Cloud Anchor service and, if successful, returns cloud anchors currently hosted in the room. The sample app uses the transforms of returned cloud anchors to render the Andy Android objects attached to them.

Next steps

Send feedback about...