Skip to main content

Quick Start

Get your first UG Labs conversation running in Unity in under 5 minutes.

Prerequisites

Import Example Scene

The SDK includes example scenes to help you get started quickly.

  1. In the Unity Editor, navigate to Samples in the Package Manager
  2. Find UG SDK and click Import next to "Examples"
  3. Open the example scene: Assets/Samples/UG SDK/[version]/Examples/SimpleConversation.unity
  4. Enter your access token in the ConversationManager component
  5. Press Play

Option 2: Create From Scratch

Follow the Usage Example guide for step-by-step instructions.

Set Your Credentials

Before running any conversation, you need to authenticate:

Method 1: Inspector (Quick Testing)

  1. Select the GameObject with your conversation script
  2. In the Inspector, find the Access Token field
  3. Paste your access token
Security

Never commit access tokens to version control. Use this method only for quick testing.

Store credentials securely and load at runtime:

using UnityEngine;
using UGSDK;

public class ConversationStarter : MonoBehaviour
{
private void Start()
{
// Load from secure storage (PlayerPrefs, Keychain, etc.)
string accessToken = LoadSecureToken();
UGSDK.Instance.Initialize(accessToken);
}

private string LoadSecureToken()
{
// Your secure token loading logic
return PlayerPrefs.GetString("UG_ACCESS_TOKEN", "");
}
}

Your First Conversation

Here's a minimal example to start a conversation:

using UnityEngine;
using UGSDK;

public class SimpleChat : MonoBehaviour
{
private Conversation conversation;

async void Start()
{
// Initialize SDK
await UGSDK.Instance.Initialize("your-access-token-here");

// Create conversation configuration
var config = new ConversationConfiguration
{
Prompt = "You are a helpful assistant in a Unity game.",
Utilities = null
};

// Start conversation
conversation = await UGSDK.Instance.StartConversation(config);

// Subscribe to events
conversation.OnTextReceived += OnTextReceived;
conversation.OnAudioReceived += OnAudioReceived;
conversation.OnInteractionComplete += OnInteractionComplete;

// Send first message
await conversation.SendMessage("Hello! Tell me about yourself.");
}

private void OnTextReceived(string text)
{
Debug.Log($"AI: {text}");
}

private void OnAudioReceived(byte[] audioData)
{
// Play audio (handled automatically by SDK)
Debug.Log($"Received {audioData.Length} bytes of audio");
}

private void OnInteractionComplete()
{
Debug.Log("Interaction complete!");
}

private void OnDestroy()
{
conversation?.Dispose();
}
}

Test the Conversation

  1. Attach the script to a GameObject in your scene
  2. Replace "your-access-token-here" with your actual token
  3. Press Play in the Unity Editor
  4. Check the Console for the AI's response

You should see:

AI: Hello! I'm an AI assistant designed to help you...
Received 8192 bytes of audio
Interaction complete!

Add Voice Input

To enable voice input, use the built-in recording functionality:

using UnityEngine;
using UnityEngine.UI;
using UGSDK;

public class VoiceChat : MonoBehaviour
{
public Button recordButton;
private Conversation conversation;
private bool isRecording = false;

async void Start()
{
await UGSDK.Instance.Initialize("your-access-token-here");

var config = new ConversationConfiguration
{
Prompt = "You are a voice assistant in a game."
};

conversation = await UGSDK.Instance.StartConversation(config);
conversation.OnTextReceived += OnTextReceived;

recordButton.onClick.AddListener(ToggleRecording);
}

private async void ToggleRecording()
{
if (!isRecording)
{
await conversation.StartRecording();
isRecording = true;
recordButton.GetComponentInChildren<Text>().text = "Stop";
}
else
{
await conversation.StopRecording();
isRecording = false;
recordButton.GetComponentInChildren<Text>().text = "Record";
}
}

private void OnTextReceived(string text)
{
Debug.Log($"AI: {text}");
}
}

What's Next?

Now that you have a basic conversation working:

Common Issues

"Unauthorized" Error

  • Verify your access token is correct
  • Check that the token hasn't expired
  • Ensure you're using the correct API endpoint

No Audio Playback

  • Check device volume
  • Verify microphone permissions are granted
  • Test on a physical device (not simulator)

WebSocket Connection Failed

  • Check your internet connection
  • Verify the API endpoint URL
  • Look for firewall/proxy blocking WebSocket connections

Getting Help

If you run into issues: