# Building for AR

## AR Installation

If you want to make your Convai Plugin compatible with AR, you can do so in two ways. Please see the instructions below or check out our [*latest tutorial video*](https://www.youtube.com/watch?v=j0l_paOQxvI) on YouTube.

{% embed url="<https://www.youtube.com/watch?v=j0l_paOQxvI>" %}

### Method 1 : Automatic Setup

{% hint style="success" %}
Recommended for new projects.
{% endhint %}

{% hint style="danger" %}
The following processes will be performed:

* Universal Render Pipeline (URP)
* ARCore Plugin
* Convai Custom AR Package
* Convai URP Converter

**If these packages are not present, they will be installed.**
{% endhint %}

{% hint style="danger" %}
**If the target build platform is not Android, it will be switched to&#x20;*****Android.***
{% endhint %}

{% hint style="warning" %}
Make sure to download the Android platform support from Unity Hub for your project's version.
{% endhint %}

1. Click on " *Convai / Convai Custom Package Installer / Install AR Package* "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F21bOM5YePk9F46dEKSkr%2FConvaiCustomPackageInstaller.png?alt=media&#x26;token=c20d32f6-aff5-459f-8213-e0ce83bc8f1d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Flwyrdwq0Bhq58VGc9Bjh%2FConvaiCustomPackageInstallerWindowAR.png?alt=media&#x26;token=0a8e168d-3209-4723-9e09-9fb53f1f1ca5" alt=""><figcaption></figcaption></figure>

2. Confirm the changes and processes to be made. If you agree, the process will start.                     Click " **Yes, Proceed** " and the process will begin. You'll see logs in the console.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4ws6CGWsLFJ6zLxNKPSq%2FConvaiCustomPackageInstallerConfirmWindowAR.png?alt=media&#x26;token=56e44ae6-4e61-4a0a-97b0-d2a4b1f87c6a" alt=""><figcaption></figcaption></figure>

3. If you encounter an error like "Failed to Resolve Packages," don't worry. The process will continue, and the error will be resolved automatically after the package installations are complete.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F7fUslCWtZqtvEOwM2uOH%2FARLogs.png?alt=media&#x26;token=721a834b-14a5-405c-be84-0f49fea4b76f" alt=""><figcaption></figcaption></figure>

4. Open the " *Convai / Scenes / Convai Demo - AR* " demo scene. If the TMP Importer window appears ( It will appear if TMP Essentials is not installed in your project ), click " **Import TMP Essentials** " to install TextMeshPro Essentials for UI text objects.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F69nbgYYrti9eBL9Ogfbo%2FAutomaticallyImportTMPEssentials.png?alt=media&#x26;token=31bdc58f-c282-4d6d-88db-8ff7ae9a1045" alt=""><figcaption></figcaption></figure>

Alternatively, you can use the " *Window / TextMeshPro / Import TMP Essential Resources* " to install it.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F22hL0PzDtgfJUMUbapkX%2FManualImportTMPEssentialsResources.png?alt=media&#x26;token=2fee2d5c-8622-419b-8069-6d7a643c6930" alt=""><figcaption></figcaption></figure>

5. After importing TMP Essentials, you can remove the empty GameObject in your scene that triggers the Prompt window to appear.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FarFsZNk1OQh5m0fcLaO8%2FTMPEssentialsPromptImportReminder.png?alt=media&#x26;token=aeb76ac0-cb3c-4ecc-9e83-331a8580d83b" alt=""><figcaption></figcaption></figure>

6. Build your project by going to " *File / Build Settings / Build* " Ensure that the " **Convai Demo - AR** " scene is included in the Scenes in Build section.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FuB4yzjkFGUuh3wCKX73i%2FARBuildSettings.png?alt=media&#x26;token=e7efa07c-af7f-47b0-83b9-8cc30084f74d" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Ensure you've set up your API Key. ( Convai / Convai Setup )
{% endhint %}

Now everything is ready for testing. 🙂✅

### Method 2 : Manual Setup&#x20;

{% hint style="danger" %}
Ensure you have the following packages installed in your project:

* ARCore
* URP (Universal Render Pipeline) - Recommended for optimization, though not mandatory
  {% endhint %}

1. Double-click on " Convai / Convai Custom Unity Packages / ConvaiVRUpgrader.unitypackage "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FDggXobNOFr7cSrnCzK90%2FConvaiARUpgrader.png?alt=media&#x26;token=774504b7-fd30-4610-a657-6e0202328638" alt=""><figcaption></figcaption></figure>

2. You'll see a warning that the settings will overwrite your project settings. You can either allow it by clicking " **Import** " or create a temporary project by clicking " **Switch Project** "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FO3QHQ8judZcL0A8Y7srx%2FVRUpgraderWarning.png?alt=media&#x26;token=73944c2f-6c54-4cb5-bb44-dad6e2d8e146" alt=""><figcaption></figcaption></figure>

3. In the Import Unity Package window, review the assets to be imported and click " **Next** "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FArOZ4GHGtbhnDlzD1xnc%2FConvaiARUpgraderimport_1.png?alt=media&#x26;token=391c7980-d70b-4b26-9212-9beb6509cf31" alt=""><figcaption></figcaption></figure>

4. Select all settings to be changed in the Project Settings and complete the installation by clicking    " **Import** "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FbLCiJ1utUvadjKRyD9hC%2FConvaiARUpgraderimport_2.png?alt=media&#x26;token=8f065030-203a-46db-9504-2414dd463d36" alt=""><figcaption></figcaption></figure>

5. Open the " *Convai / Scenes / Convai Demo - AR* " demo scene. If the TMP Importer window appears ( It will appear if TMP Essentials is not installed in your project ), click " **Import TMP Essentials** " to install TextMeshPro Essentials for UI text objects.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F69nbgYYrti9eBL9Ogfbo%2FAutomaticallyImportTMPEssentials.png?alt=media&#x26;token=31bdc58f-c282-4d6d-88db-8ff7ae9a1045" alt=""><figcaption></figcaption></figure>

Alternatively, you can use the " *Window / TextMeshPro / Import TMP Essential Resources* " to install it.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F22hL0PzDtgfJUMUbapkX%2FManualImportTMPEssentialsResources.png?alt=media&#x26;token=2fee2d5c-8622-419b-8069-6d7a643c6930" alt=""><figcaption></figcaption></figure>

6. After importing TMP Essentials, you can remove the empty GameObject in your scene that triggers the Prompt window to appear.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FarFsZNk1OQh5m0fcLaO8%2FTMPEssentialsPromptImportReminder.png?alt=media&#x26;token=aeb76ac0-cb3c-4ecc-9e83-331a8580d83b" alt=""><figcaption></figcaption></figure>

7. If you see 3D objects in pink, it's a shader issue. If you're using URP, convert the materials to URP by double-clicking on " *Convai / Convai Custom Unity Packages / ConvaiURPConverter* " and importing all assets in the window that appears.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FR9jINUQqbrd9jZp4SCYV%2FConvaiURPConverter.png?alt=media&#x26;token=25651447-64c9-44d4-890b-0ab8823609eb" alt=""><figcaption></figcaption></figure>

8. Ensure you've set up your API Key ( Convai / Convai Setup ).
9. Build your project by going to " *File / Build Settings / Build* " Ensure that the " **Convai Demo - AR** " scene is included in the Scenes in **Build** section.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FuB4yzjkFGUuh3wCKX73i%2FARBuildSettings.png?alt=media&#x26;token=e7efa07c-af7f-47b0-83b9-8cc30084f74d" alt=""><figcaption></figcaption></figure>

Now everything is ready for testing. 🙂✅

## How to Add and Adjust Size Of My Own Character?

If you've created a Ready Player Me character on convai.com playground and want to add it to your AR project, follow these steps:

1. Right-click on the " *Convai / ConvaiAR / Prefabs / Convai NPC AR Base Empty Character* " prefab.
2. Click on " *Create / Prefab Variant* "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FZx9OGFsUywqr8HuLX4Re%2FCreatePrefabVariant.png?alt=media&#x26;token=2dfcb125-7329-4714-84bb-b178c47f08bd" alt=""><figcaption></figcaption></figure>

3. You'll see a prefab variant created for " **Convai NPC AR Base Empty Character** "
4. Double-click on this prefab variant.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F3ErM8IB9Wq5wkaScGpTJ%2FOpenCharacterVariant.png?alt=media&#x26;token=5d8456dd-95a3-4b70-bcf1-c8388e2e8c02" alt=""><figcaption></figcaption></figure>

5. In the Hierarchy section, add your imported character as a child to this prefab variant.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F85G257QOnLmYmyUOZqA7%2FAddYourCharacter.png?alt=media&#x26;token=44694407-8480-414f-8416-dffcc99e17c2" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Use the " [unity-importing-ready-player-me-rpm-characters](https://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin/unity-importing-ready-player-me-rpm-characters "mention") " guide to add your character to your project.
{% endhint %}

6. After adding your character, click on your character.
7. In the Inspector, adjust the Scale settings as needed. To prevent your character from moving with animation while talking, disable the " **Apply Root Motion** " option in the Animator.            &#x20;

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FSnAI1C9drxtaDXG8JLSC%2FSetScaleOfYourCharacterandDisableRootMotion.png?alt=media&#x26;token=671a09e7-b71e-4003-82f1-a6558710c6c1" alt=""><figcaption></figcaption></figure>

8. After these steps, save your prefab variant by pressing **CTRL + S**.
9. Open the " *Convai / Scenes / Convai Demo - AR* " scene.
10. Click on the " **Convai AR Player** " object under " **ConvaiAR Base Scene** "

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FlAlWy7ujVI3ugUWrzuzn%2FOpenConvaiARPlayer.png?alt=media&#x26;token=e302dc34-86f3-47d6-a765-0a96d03f66fc" alt=""><figcaption></figcaption></figure>

11. In the Inspector, under the " **Convai Character Spawner** " component, add your prefab variant to the **Character Prefab** field.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FCCM19jnfXclZD2oaSHMY%2FAddYourCharacterPrefab.png?alt=media&#x26;token=51e5edb2-1dec-4061-81ec-eabe4543e552" alt=""><figcaption></figcaption></figure>

Now, everything is ready to test your character in the AR environment!🙂✅

{% hint style="success" %}
Creating this prefab variant is to prevent automatic scaling ( 1,1,1 ) of your prefab when instantiated in the AR environment.&#x20;

To avoid issues with scale adjustments, we added our character as a child to an empty parent object. For convenience, we created an empty prefab variant.
{% endhint %}
