Building Your Own Dialogue UI
Show lines and choices in your own UI, driven by the Dialogue Manager.
The Dialogue Box can cover most games and use cases. For something different (speech bubbles over characters, phone chat, etc.), you can play the story in your own UI. You only write the part players see. Poetix still runs the story: it checks conditions, applies results, fills in {{variables}}, and picks the next line and beat.
Your UI listens to two events and answers with two calls. This guide assumes you've read Controlling Dialogue from Code, which introduces the Poetix class.
Set up the scene#
Instead of a Dialogue Box, add a Dialogue Manager on its own: in the Hierarchy, right-click and choose Poetix > Dialogue Manager, then set its Story. It plays the story but draws nothing.
Everything else works as before. Dialogue Starters find this Dialogue Manager by themselves, and Poetix.Play, Poetix.BlockInput, the variables, and saving all behave the same way.

Lines and choices#
Poetix.LineReadyfires with each line to show, aSimLine. Show itsSpeakerName(empty for a line with no character) andText. When the player moves on, callPoetix.Continue().Poetix.ChoicesReadyfires right after the last line of a beat that has choices, in the same frame. Show the choices with that last line. EachSimChoicehas itsTextand whether its condition passed. When the player picks one, callPoetix.Choose(choice).Poetix.StartedandPoetix.Endedtell you when to open and close your UI.
Continue does nothing while choices are waiting, so a Next button left on screen can't skip a choice. If every choice of a beat failed its condition, there's nothing to pick, and Continue ends the conversation instead.
A complete example#
This UI has a panel with the speaker's name, the line, a Next button, and a list that gets one button per choice. Connect the fields in the Inspector, and make choicePrefab a Button with a TextMesh Pro label.
using System.Collections.Generic;
using PoetixSDK;
using PoetixSDK.Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class MyDialogueUI : MonoBehaviour
{
[SerializeField] private GameObject panel;
[SerializeField] private TMP_Text speaker;
[SerializeField] private TMP_Text body;
[SerializeField] private Button nextButton;
[SerializeField] private Transform choiceList;
[SerializeField] private Button choicePrefab;
void OnEnable()
{
Poetix.Started += Open;
Poetix.Ended += Close;
Poetix.LineReady += ShowLine;
Poetix.ChoicesReady += ShowChoices;
nextButton.onClick.AddListener(Poetix.Continue);
// Turned on in the middle of a conversation? Catch up.
panel.SetActive(Poetix.IsPlaying);
if (Poetix.CurrentLine != null) ShowLine(Poetix.CurrentLine);
if (Poetix.CurrentChoices.Count > 0) ShowChoices(Poetix.CurrentChoices);
}
void OnDisable()
{
Poetix.Started -= Open;
Poetix.Ended -= Close;
Poetix.LineReady -= ShowLine;
Poetix.ChoicesReady -= ShowChoices;
nextButton.onClick.RemoveListener(Poetix.Continue);
}
void Open() => panel.SetActive(true);
void Close() => panel.SetActive(false);
void ShowLine(SimLine line)
{
speaker.gameObject.SetActive(line.SpeakerName != "");
speaker.text = line.SpeakerName;
body.text = line.Text;
ClearChoices();
nextButton.gameObject.SetActive(true);
}
void ShowChoices(IReadOnlyList<SimChoice> choices)
{
bool anyToPick = false;
foreach (var choice in choices)
{
if (choice.ConditionEval?.Result == false) continue; // condition failed: leave it out
var button = Instantiate(choicePrefab, choiceList);
button.GetComponentInChildren<TMP_Text>().text = choice.Text;
button.onClick.AddListener(() => Poetix.Choose(choice));
anyToPick = true;
}
// Every choice locked? Then Next ends the conversation.
nextButton.gameObject.SetActive(!anyToPick);
}
void ClearChoices()
{
foreach (Transform child in choiceList) Destroy(child.gameObject);
}
}Start a conversation the usual way, with a Dialogue Starter or Poetix.Play, and it appears in your UI.
Things Poetix handles for you#
- Conditions and results: a line whose conditions fail never reaches
LineReady, and results are applied before the line is shown. Auto-choice beats move on by themselves. - Variables in text:
{{Gold}}in a line or a choice is already replaced with its value. - Double presses:
ContinueandChooseare ignored in the frame the line or choices appeared. A key handled by both your UI and another script answers only once, and the press that brought up the choices doesn't also pick one. - Locked choices:
Chooserefuses a choice whose condition failed, so showing one greyed out is safe.
Showing locked choices#
The example leaves out choices whose condition failed. To show them greyed out instead, so players know there was another way, keep them and make their button non-interactable:
bool locked = choice.ConditionEval?.Result == false;
button.interactable = !locked;ChoiceDisplayBuilder.Build, in PoetixSDK.Core, does the same sorting the Dialogue Box uses. It gives you each choice's label with an optional number ("1. "), whether it's locked, the condition that locked it, and its number key:
foreach (var entry in ChoiceDisplayBuilder.Build(choices, includeLocked: true, numberFormat: "{0}. "))
{
// entry.Label, entry.IsLocked, entry.LockReason, entry.Number, entry.Id
}What's up to your UI#
With your own UI, Poetix doesn't draw or animate anything. These are yours to add, if your game wants them:
- Typing text out letter by letter. TextMesh Pro's
maxVisibleCharactersis a simple way. - Keys: the example uses buttons. For keyboard or gamepad, call
Poetix.Continue()andPoetix.Choose(index)from your input code.Choose(index)counts only choices whose condition passed, starting from 0. - Portraits: the line's
CharacterIdfinds the character's downloaded portrait withstoryAsset.GetPortrait(line.CharacterId). - Sounds and input blocking: check
Poetix.IsInputBlockedbefore acting on your own keys, so your UI stays quiet while menus are open. - A backlog:
Poetix.HistoryandPoetix.HistoryAdded(see The conversation history).
The API Reference lists every property of SimLine and SimChoice.