Unity SDK
Load your Ava-Twin avatar into any Unity scene in minutes. The SDK handles downloading, setup, animations, and caching — you just provide the URL.
Installation
Option 1: Unity Package Manager (recommended)
Install directly from your dashboard using a Git URL:
- 1. Log in to your Ava-Twin dashboard and go to Apps → SDK to copy your package URL.
- 2. In Unity, open Window → Package Manager.
- 3. Click + and select Add package from git URL…
- 4. Paste your package URL and click Add.
Option 2: Manual installation
If you prefer not to use Git, you can download the package directly:
- 1. Go to your dashboard and navigate to Apps → SDK → Downloads.
- 2. Download the latest
.unitypackagefile. - 3. In Unity, go to Assets → Import Package → Custom Package… and select the downloaded file.
- 4. Click Import to add all SDK files to your project.
Quick Start
Get an avatar running in your scene in under five minutes:
- 1. Import the Ava-Twin SDK package (see Installation).
- 2. Create an empty GameObject in your scene and add the
AvaTwinManagercomponent to it. - 3. In the Inspector, paste your API Key (from your dashboard under Apps → API Keys).
- 4. Add a
CharacterLoadercomponent to the same or another GameObject. - 5. Set the avatar URL from the Ava-Twin customizer and press Play.
Or initialize everything from code:
using AvaTwin;
using UnityEngine;
public class AvatarLoader : MonoBehaviour
{
[SerializeField] private string apiKey = "your-api-key-here";
[SerializeField] private string appId = "your-app-id-here";
async void Start()
{
// Initialize the SDK with your API key
var manager = AvaTwinManager.Instance;
manager.Initialize(apiKey);
// Load the avatar into the scene
var avatar = await manager.LoadAvatar(appId);
avatar.transform.SetParent(transform);
}
}ScriptableObject configs or load keys from a secure backend at runtime. See Configuration for recommended patterns.The SDK takes it from there — downloading the avatar model, setting up the character controller, configuring animations, and caching the result for future loads.
API Reference
AvaTwinManager
Singleton that manages SDK initialization, avatar loading, and global configuration. Access it from anywhere via AvaTwinManager.Instance.
AvatarInstance
Represents a loaded avatar in the scene. Returned by LoadAvatar() and LoadAvatarFromUrl().
CharacterLoader
MonoBehaviour component for loading avatars via the Inspector or at runtime. Attach it to any GameObject in your scene.
Loading an Avatar
There are two ways to load avatars — pick whichever fits your workflow:
Via the Inspector
Attach CharacterLoader to a GameObject, paste your avatar URL in the Inspector, enable AutoLoad, and press Play. No code required.
Via code
For dynamic scenarios like avatar selection screens, load avatars at runtime:
using AvaTwin;
using UnityEngine;
public class AvatarSelector : MonoBehaviour
{
[SerializeField] private CharacterLoader characterLoader;
[SerializeField] private Transform spawnPoint;
// Called when the player picks an avatar in your UI
public async void OnAvatarSelected(string avatarUrl)
{
// Load and instantiate the selected avatar
await characterLoader.LoadAndInstantiateAsync(avatarUrl);
// Position it at the spawn point
characterLoader.transform.position = spawnPoint.position;
characterLoader.transform.rotation = spawnPoint.rotation;
}
}Using AvaTwinManager directly
For more control, use the manager singleton:
using AvaTwin;
using UnityEngine;
public class GameManager : MonoBehaviour
{
[SerializeField] private string apiKey = "your-api-key-here";
[SerializeField] private string appId = "your-app-id-here";
private AvatarInstance currentAvatar;
async void Start()
{
AvaTwinManager.Instance.Initialize(apiKey);
// Load avatar
currentAvatar = await AvaTwinManager.Instance.LoadAvatar(appId);
currentAvatar.transform.position = Vector3.zero;
// Play idle animation
currentAvatar.SetAnimation("idle");
// Set a facial expression
currentAvatar.SetExpression("smile", 0.5f);
}
void OnDestroy()
{
// Clean up when done
currentAvatar?.Dispose();
}
}Dispose() on avatars you no longer need, especially in WebGL builds where memory is limited.Customizer Integration
The Ava-Twin Customizer lets your players build and personalize their own avatars. Here's how to integrate it into your Unity project.
Opening the Customizer from Unity
In WebGL builds, open the customizer in a browser overlay. On desktop/mobile platforms, open it in the system browser:
using AvaTwin;
using UnityEngine;
public class CustomizerButton : MonoBehaviour
{
[SerializeField] private string apiKey = "your-api-key-here";
[SerializeField] private string appId = "your-app-id-here";
public async void OpenCustomizer()
{
// Mint a secure session token
var token = await AvaTwinManager.Instance.MintCustomizerToken(appId);
// Build the customizer URL
string url = $"https://customizer.ava-twin.me?token={token}";
// Open in browser
Application.OpenURL(url);
}
}Receiving customization updates
After a player saves their avatar in the customizer, you need to load the updated model. There are two approaches:
GetAvatarConfig(). Good for turn-based games or lobby screens where real-time updates aren't critical.using AvaTwin;
using UnityEngine;
public class AvatarUpdater : MonoBehaviour
{
[SerializeField] private CharacterLoader characterLoader;
[SerializeField] private string appId = "your-app-id-here";
// Poll for updates (call on a timer or after returning from customizer)
public async void CheckForUpdates()
{
var config = await AvaTwinManager.Instance.GetAvatarConfig(appId);
if (config.LastModified > lastKnownUpdate)
{
// Avatar was changed — reload it
await characterLoader.LoadAndInstantiateAsync(config.GlbUrl);
lastKnownUpdate = config.LastModified;
}
}
private System.DateTime lastKnownUpdate;
}Demo Scene
The SDK ships with a ready-to-play demo scene. Import it from Package Manager:
- 1. Open Window → Package Manager and select the Ava-Twin SDK package.
- 2. Open the Samples tab and click Import next to Demo Scene.
- 3. Open the imported scene, paste your avatar URL into CharacterLoader, and press Play.
Controls
The demo scene comes with keyboard and mouse controls out of the box:
These bindings are configured in Edit → Project Settings → Input Manager and can be changed to suit your game.
Configuration
Fine-tune SDK behavior to match your project's requirements.
Quality settings
// Set quality before loading avatars AvaTwinManager.Instance.SetQuality(AvatarQuality.Medium);
Caching
The SDK caches downloaded avatars locally to avoid re-downloading on every session. Caching is enabled by default.
Secure API key management
For production builds, avoid embedding your API key directly in the build:
using AvaTwin;
using UnityEngine;
// Create a ScriptableObject to hold your config
[CreateAssetMenu(fileName = "AvaTwinConfig", menuName = "Ava-Twin/Config")]
public class AvaTwinConfig : ScriptableObject
{
[Tooltip("Your API key from the Ava-Twin dashboard")]
public string apiKey;
[Tooltip("Your app ID from the Ava-Twin dashboard")]
public string appId;
}
// Load it at runtime
public class SecureInitializer : MonoBehaviour
{
[SerializeField] private AvaTwinConfig config;
void Start()
{
AvaTwinManager.Instance.Initialize(config.apiKey);
}
}.gitignore. Each team member should create their own local config with their API key.