Quick Start
Get your first UG Labs conversation running in Unity in under 5 minutes.
Prerequisites
- Unity 6 or later installed
- UG Labs SDK installed (Setup Guide)
- UG Labs access token (get one from console.stg.uglabs.app)
Import Example Scene
The SDK includes example scenes to help you get started quickly.
Option 1: Use Example Scene (Recommended)
- In the Unity Editor, navigate to Samples in the Package Manager
- Find UG SDK and click Import next to "Examples"
- Open the example scene:
Assets/Samples/UG SDK/[version]/Examples/SimpleConversation.unity - Enter your access token in the
ConversationManagercomponent - 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)
- Select the GameObject with your conversation script
- In the Inspector, find the Access Token field
- Paste your access token
Security
Never commit access tokens to version control. Use this method only for quick testing.
Method 2: Runtime (Recommended)
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
- Attach the script to a GameObject in your scene
- Replace
"your-access-token-here"with your actual token - Press Play in the Unity Editor
- 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:
- Usage Example - Learn about all SDK features
- Conversation Events - Handle all event types
- API Reference - Understand the underlying protocol
- Examples - See more complete examples
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:
- Check the Unity SDK GitHub Issues
- Review the API Documentation
- Contact support at support@uglabs.app