Multi-AR Tips and Tricks

Here are some tips and tricks regarding the ‘Multi-AR Examples’-asset. By publishing them here, it will be easier for me, to keep the AR-related knowledge base in one place. There are many tricky things to keep in mind in this area. And many more will come soon, because AR is a hot topic, and will become even hotter in the future.

Here is a link to the Online documentation of the Multi-AR-asset.

 

Table of Contents:

How to use the Multi-AR-package functionality in your own Unity project
How to anchor a scene object to the world
How to run the networking client-server demo

 

How to use the Multi-AR-package functionality in your own Unity project

1. Copy folder ‘MultiAR’ from the Assets-folder of the package to the Assets-folder of your project. This folder contains the package scripts, AR-platform interfaces and needed resources. It includes Multi-AR demo scenes, as well. You can delete MultiAR/DemoScenes-folder to save space.
2. Copy folder ‘GoogleARCore’ from the Assets-folder of the package to the Assets-folder of your project. This folder contains Google AR-Core scripts, libraries and resources. It includes the AR-Core demo scenes, as well. You can delete the GoogleARCore/Examples-folder to save space.
3. Copy folder ‘UnityARKitPlugin’ from the Assets-folder of the package to the Assets-folder of your project. It contains Apple AR-Kit scripts, libraries and resources. It includes the AR-Kit demo scenes, as well. You can delete the UnityARKitPlugin/Examples-folder to save space.
4. Open the project in Unity editor. There shouldn’t be any errors in the console.
5. Add the MultiARController-prefab from MultiAR/CoreScripts/Prefabs-folder to the scene, if it is not yet there. You are all set now.

How to anchor a scene object to the world

Here is how to anchor a game object in the scene (called ‘obj’ in the code below) to the world point, where the user taps. This world point should belong to a detected surface.

MultiARManager arManager = MultiARManager.Instance;

if (obj && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true))
{
	MultiARInterop.InputAction action = arManager.GetInputAction();

	if (action == MultiARInterop.InputAction.Click)
	{
		MultiARInterop.TrackableHit hit;
		if(arManager.RaycastToWorld(true, out hit))
		{
			arManager.AnchorGameObjectToWorld(obj, hit);
		}
	}
}

How to run the networking client-server demo (v2.4 and later)

This example consists of two scenes in DemoScenes/NetworkDemo-folder. It uses the Google cloud anchors, to share the AR playground among the clients. The ArServerDemo-scene is a dedicated game server that stores the shared cloud anchor ID and synchronizes the clients and players. The simple multiplayer game, world anchoring and cloud anchor sharing is done in the ArClientDemo-scene. Here is how to setup and run these demo scenes.

1. Build the ARServerDemo-scene for Standalone platform (Windows or MacOS-X). It is a simple dedicated game server. Its purpose is to share the cloud anchor ID among the clients, and synchronize the players.
2. You can build the ArClientDemo-scene on either Android or iOS devices, because Google cloud anchors work on both AR-Core and AR-Kit platforms. In this regard, first you need to get your AR-Core API Key, needed for cloud anchor sharing (i.e. saving and restoring).
3. To get a cloud anchor API go to this page and look for ‘ARCore Cloud Anchor API’. One found, select and enable the API. Create a cloud project as well, if needed.
4. Then go to this page and create a new API key. Copy the newly created key to the clipboard.
5. Go back to the Unity editor. Open menu ‘Edit / Project settings / ARCore’ and paste the copied key to its ‘Cloud services API key’-field.
6. Select the ClientController-object in Hierarchy, and look at its ArClientController-component. As you see, ‘Server host’ is set to ‘0.0.0.0’. This means the client will utilize network discovery, to find the game server automatically. If this doesn’t work, you can set this setting to the server machine’s IP address (or name) instead.
7. Run the server, then build and run the client(s). When the first client connects to the server and some AR surfaces are detected, you may tap on a detected surface to anchor the playground to the world, and save this anchor to the cloud. The other clients will get the anchor Id from the server and try to restore the same anchor from the cloud. Hence, all clients (players) will share the same play area. After the play area is set, tap to shoot the other players.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s