Use Cloud Anchors to build AR experiences that Android and iOS users can share.
This guide assumes that you have already downloaded the ARCore SDK for Unity and imported it into a Unity project targeting iOS.
If not, see the Quickstart for iOS for installation and configuration instructions.
If you are new to working with anchors, see Working with anchors for an introduction.
Use Cloud Anchors
Set up your development environment for working with Cloud Anchors and try out the sample app.
About Cloud Anchors ID sharing
The CloudAnchors 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 Anchor API in your app, you'll need an API Key.
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.
Enable the ARCore Cloud Anchor API for your Google Cloud Platform project.
Add your API key to your project:
- In Unity, go to Edit > Project Settings > Google ARCore.
- Add your API key to the Cloud Services API Key field.
Open the sample scene
The CloudAnchors sample is included with the ARCore SDK for Unity.
- In the Unity Project window, you can find the CloudAnchors.unity sample in:
Configure build and platform settings
Add the sample scene to your build:
- Go to File > Build Settings and click Add open scene.
- Select CloudAnchors. Disable any other scenes in the build.
Try out the sample app
Launch the app
Go to your Xcode output folder and open the
Unity-iPhone.xcworkspacefile in Xcode.
To avoid build errors, do not build or launch from the included
In Xcode, select the
Unity-iPhoneproject in the left pane, connect your phone, and launch the app.
Host and resolve Cloud Anchors
The sample app launches on your phone. Create a room with the host device. The app will display a room code which can be used to join this room from another device.
Move your phone around until ARCore starts detecting and visualizing planes.
Tap a plane to create an anchor object on it. 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.
After the Cloud Anchor is successfully hosted, subsequent taps will create Star objects, which will be synchronized across devices using Unity Multiplayer Services.
Launch the example from a new device, and join the room you created previously. A request is sent to the Google Cloud Anchor service to resolve the pose of the cloud anchor. When this request returns successfully, the sample app renders the anchor using the pose.
Both devices will now be able to tap the screen to place Stars.