Simple Shared AR experience: Initialization

In this chapter, we'll cover how to add and initialize ConjureKit to a new Unity project.

Preparing the project with ARFoundation

  1. Configure the project for XR development. Go to Edit -> Project Settings -> XR Plug-In Management
    • -> iOS and enable the ARKit checkbox for iOS devices.
    • -> Android and enable the ARCore checkbox for Android devices.
  2. Configure build parameters. Go to Project Settings -> Player
    • -> iOS -> Other Settings -> Camera Usage Description and write a camera description, e.g., "AR requires a camera".
      • On Android, this permission is automatically added to manifest on build. Android will ask for Camera permissions when the app will first run.
    • -> Android -> Other Settings and have
      • Auto Graphics API disabled and OpenGLES3 at the top of the list
      • Scripting backend set to IL2CPP and both ARMv7 and ARM64 selected in Target Architectures
  3. Go to Package Manager -> Unity Registry, and Install ARFoundation.

start-warning

We suggest to check which ARFoundation and ARKit/ARCore package versions are installed by Package Manager, as they might not be equal. This is not automatically handled when installing a "Preview" version and mismatch can happen.

end-warning

start-note

ARFoundation versions below 4.2.6 do not support iOS 16.

end-note

  1. Start with an empty scene with no GameObjects.
  2. Create a new AR Session Origin by selecting GameObject -> XR -> AR Session Origin.
  3. Add a new ARTrackedImageManager component to the AR Session Origin GameObject.
  4. Create a new ReferenceImageLibrary by selecting Assets -> Create -> XR -> Reference Image Library. and drag it to the “serialized library” field in the ARTrackedImageManager component.
  5. Set "Max Number Of Moving Images" field in the ARTrackedImageManager component to 1.
  6. Create a new AR Session by selecting GameObject -> XR -> AR Session.
Scene setup after adding ConjureKit

Initializing ConjureKit

1. Install the ConjureKit package.

2. Create a new ^MonoBehaviour^ script and attach it to an empty game object in the scene.

3. Import ^ConjureKit^.

using Auki.Ur;

4. Create a private ^IConjureKit^.

private IConjureKit _conjureKit;

5. Create a public ^Camera^ variable.

public Camera arCamera;

6. Drag the AR Camera to the ^arCamera^ field on the GameObject you created;

Scene setup

7. Initialize ^ConjureKit^ with the app key and secret from the posemesh console (cf. the Quickstart guide)

start-warning

Never share your app secret with anyone.

end-warning

8. Call ^_conjureKit.Connect()^ to connect to a Relay server with the lowest latency and create a session.

using Auki.ConjureKit;

public class ConjureKitDemo : MonoBehaviour
{
    public Camera arCamera;

    private IConjureKit _conjureKit;

    private void Start()
    {
        _conjureKit = new ConjureKit(
            arCamera.transform,
            "YOUR_APP_KEY",
            "YOUR_APP_SECRET");


        _conjureKit.Connect();
    }
}

9. Declare two new ^Text^ fields to display the session ID and session state on screen.

[SerializeField] private Text sessionState;
[SerializeField] private Text sessionID;

10. Register a callback to the ^_conjureKit.OnStateChanged^ event that fires every time our session state changes.

_conjureKit.OnStateChanged += state =>
{
    sessionState.text = state.ToString();
};

11. Register callback to ^_conjureKit.OnJoined^ and ^_conjureKit.OnLeft^ which are triggered when we join and leave a session.

_conjureKit.OnJoined += session =>
{
    sessionID.text = session.Id;
};

_conjureKit.OnLeft += session =>
{
    sessionID.text = "";
};

12. Create two ^Text^ elements and drag and drop them to the fields you declared in step 8.

13. Click Play in Unity Editor. Now you'll see the state of your connection logged in the console and session id and state on the screen.

Session ID
This is the beginning of this lesson

Need a refresher on the essentials?

Check out more lessons, DIY kits and essentials reading material at the developer learning centre homepage.

Want to build on the posemesh and need a helping hand?

Apply for a grant of AUKI tokens to get your project off the ground, and work directly with the Auki Labs team to get your creation to market. Successful applicants may be granted up to 100k USD worth of AUKI tokens, and development and marketing support from the Auki Labs team.