This example showcases how to integrate a voice agent built with LiveKit Agents into a Unity project using the LiveKit Unity SDK, attaching the agent's voice and transcriptions to a world object.
-
Setup your agent: If you don't already have an agent to work with, you can follow the Voice AI Quickstart to build a simple voice agent in less than 10 minutes.
-
Clone repository:
git clone https://github.com/livekit-examples/agents-example-unity.git
- Add Project to Unity Hub: From the Unity Hub, click "Add" and select "Add project from disk." Navigate to the cloned repository, and choose the "AgentsExample" subdirectory (this is the Unity project root).
Note
When opening the project for the first time, it may take a few minutes to resolve the LiveKit SDK package.
-
Sandbox Token Server: Create a new Sandbox Token Server for your LiveKit Cloud project and take note of its ID. With the Unity project open, select
SandboxAuth
in the "Assets" directory. From the inspector, fill in the ID of your sandbox token server. -
Enter Play Mode: Click the play button at the top of the Unity Editor to start the application.
In a production environment, you will be responsible for developing a solution to generate tokens for your users which is integrated with your authentication solution. You should disable your sandbox token server and modify TokenService.cs
to use your own token server.
This project is configured to work out-of-the-box in Visual Studio Code for development, providing IntelliSense and the ability to attach to the Unity debugger. To use this configuration, open the "AgentsExample" directory in Visual Studio Code. Install the recommended extensions when prompted.
To debug, ensure Unity is running in Play mode, then use the "Attach to Unity" debug configuration.