First Inference in Unity¶
Install the Tryll Unity package, drop a TryllAgentComponent on a GameObject,
connect to the running server, send one message, and watch the streamed reply
appear in a UI Text element.
Before you start¶
- Unity 6 (6000.x) or later, with a blank 3D project.
- A running Tryll server on
127.0.0.1:9100. See Run the Tryll Server. -
The server FlatBuffers C# bindings must be generated before opening Unity for the first time. Run from the
server/folder: -
At least one language model available in the server's
models.json.
Step 1 — add the package¶
- Open your Unity project's
Packages/manifest.json. -
Add an entry pointing at the
server/client-unity/folder (adjust the relative path from your Unity project root): -
Save the file. Unity will import the package; you should see no compile errors. If you see
error CS0246: The type or namespace name 'Message' could not be found, the CMake build step above was skipped — run it and wait for Unity to reimport.
Step 2 — configure the server path (optional)¶
If you want Unity to launch the server automatically:
- Open Edit → Project Settings → Tryll Client.
- Enable Auto Launch Server.
- Set Editor Server Exe Path to the path of your built
tryll_server.exe(e.g.../server/build/server/Debug/tryll_server.exe).
Alternatively, leave this disabled and start the server manually before entering Play Mode.
Step 3 — create a workflow asset¶
- In the Project window, right-click → Create → Tryll → Workflow Asset.
- Name it
SimpleWorkflow. -
In the Inspector, expand Graph and add one node:
Field Value Nodes[0].Name genNodes[0].Type GenerateNodes[0].Params[0].Key model_nameNodes[0].Params[0].Value (name of a model in models.json) -
Add one exit route:
Field Value Routes[0].SourceNode genRoutes[0].ExitName doneRoutes[0].TargetNode END -
Set StartNode to
gen.
Alternatively, build the graph in code using TryllGraphBuilder (see
Build a chat agent with a graph).
Step 4 — set up the scene¶
- Create a new empty GameObject in the Hierarchy — call it
TryllDemo. - Add a Tryll Agent Component (
Add Component → Tryll → Tryll Agent Component). - Assign your
SimpleWorkflowasset to the Workflow Asset slot. - Enable Auto Create On Connect.
- Add a UI → Text (TMP) element to your scene for the output — name it
AnswerText. - Create a C# script
TryllDemo.csand attach it to the same GameObject:
using UnityEngine;
using TMPro;
using Tryll.Client;
public class TryllDemo : MonoBehaviour
{
public TMP_Text AnswerText;
private TryllAgentComponent _agent;
private string _accumulated = "";
void Start()
{
_agent = GetComponent<TryllAgentComponent>();
// Wire up streaming answer.
_agent.OnAnswerText.AddListener((text, isDelta, isFinal) =>
{
if (isDelta)
_accumulated += text;
else
_accumulated = text;
AnswerText.text = _accumulated;
if (isFinal)
Debug.Log("Answer complete");
});
_agent.OnTurnComplete.AddListener((status, debugInfo, tokensGenerated) =>
{
if (status != TryllTurnStatus.Success)
Debug.LogError($"Turn failed: {status}");
});
_agent.OnError.AddListener(error =>
Debug.LogError($"Tryll error: {error}"));
// Connect to the server. TryllAgentComponent will create the agent
// automatically once connected (AutoCreateOnConnect = true).
TryllClient.Instance.Connect();
}
// Call this from a UI button's OnClick.
public void SendHello()
{
_accumulated = "";
_agent.SendMessage("Hello, what can you tell me about yourself?");
}
}
- Assign the
AnswerTextreference in the Inspector. - Add a UI → Button and wire its OnClick to
TryllDemo.SendHello.
Step 5 — enter Play Mode¶
- Press Play.
- The
[TryllClient]singleton GameObject appears in the Hierarchy (created byTryllClientModule). - Click your button. You should see the answer stream in one or more chunks
in
AnswerText.
If the agent fails to create, check:
- The server is running and the model name matches exactly.
- The FlatBuffers bindings were generated (Step 0).
- The Console for any
[Tryll]-prefixed error messages.
What's next?¶
- Build a chat agent with a graph — more node types, routing, and multi-turn conversation history.
- Stream answers to your UI — delta vs. full-text streaming, accumulation patterns.
- Unity Client API Reference — complete class-level reference.