Developer Guide

Tutorial: Create a Unity app with CraftAR Augmented Reality SDK

icon Date Developer Guide

icon Date Dec 17, 2020

icon author Catchoom Team

icon folder ,

The CraftAR Augmented Reality Unity SDK provides a set of tools to create apps directly from the context menu. The very first step that you’ll need to take is to set up your Unity project. Once the project is set, you can follow the steps below. Note that you’ll need to create and publish at least one item with Unity to use the app that we’re going to create with this tutorial.

  1. Create the CraftAR app.
  2. Connect the app with your account in the CraftAR service.
  3. Build and run on your smartphone

At the end of this tutorial, we also explain the script that is generated once the app is built.

1. Create the CraftAR app

Create a new CraftAR Application by clicking on the context menu CraftAR > New CraftAR App.

Set the name of your CraftAR app script and click ‘Create’

This wizard will create a new Unity Scene, containing an object named CraftARSDK. This object provides the following capabilities in your Unity application:

  • Manage all the interaction with the CraftAR service
  • Draw the frames captured by the camera
  • Render the Augmented Reality scene.

2. Connect the app with your account in the CraftAR service

Click on the CraftARSDK Object, go to the Unity Inspector, and edit the field labeled ‘Collection token’ with the Token of your collection (see What is a token and how can I get it).

3. Build and run on your smartphone

First, set your the App ID (Bundle identifier) in order to be able to add AR items from CraftAR. We recommend that, for testing purposes you set he Bundle Identifier to com.catchoom.test

For more information about App IDs check this tutorial

In order to run this application, go to File > Build Settings and click on Add Current to set the current scene.

Plug your smartphone or tablet to your computer. Finally, click on Build And Run and select a destination.

In the case of Android, it generates an APK file and runs the application. For iOS, it launches XCode and creates a new project, compiles it and runs the application. All this process is the standard of Unity.

Once the app is running, point to an image of any of your ARItems in your collection, and the AR experience will be shown.

Script of the app we just created

If you’re curious about the script that this app runs, you can open the script to edit it. Make your script implement the CraftARSDKCallbacks interface, and all of its methods. Note that you have to use the namespace System.Collections.Generic.

In the Start() method set the current script as the callbacksHandler for the calls of the SDK.

In the CraftARReadyMethod(), you can start using all the other SDK functions. As an example, you can setup your token here. In this case, we will start the finder mode once we have validated the token in the server:

​After calling CraftARSDK.instance.startFinderMode(), you will start receiving callbacks to your SearchResults() method (or to SearchError if any error was produced). In this callback, you will receive a list of items that were found in the last request.

In this example, we will first check if any result was found. If one or more results were found, we will take just the first one, which is the one with the highest score (i.e. best match), and check if it was an AR item or an IR item. When you find an item, you may want to stop the finder mode, and show a result to the user or start the AR experience:

Go to the Unity editor, run the app, point to your AR reference image, and you should be able to see the contents drawn in top of it.

Related Posts in Developer Guide