Dialogue Runner
The Dialogue Runner is the component that runs your dialogue. You give it a Yarn Project, and it steps through your Yarn Scripts one line at a time. It hands each line and set of options to your Dialogue Presenters, calls your Commands, and keeps track of your variables.
Everything the player sees on screen comes from the Presenters.
Adding a Dialogue Runner
The quickest way to get a Dialogue Runner is the Dialogue System prefab. Open the GameObject menu and choose . It comes with a Dialogue Runner, Presenters and a Line Advancer, already connected. See Showing Dialogue.
To add a Dialogue Runner to a GameObject of your own instead, click Add Component in the Inspector and search for Dialogue Runner.
- Select the Dialogue Runner, and set Yarn Project to your
.yarnproject, by dragging it in from the Project window. - If you want the dialogue to start on its own, turn on Start Automatically, and choose which node to start from in Start Node. It’s a dropdown of the nodes in your Yarn Project, and defaults to
Start.

Most games need one Dialogue Runner. Each one runs one conversation at a time. For two conversations running at once, such as background chatter while the player talks to someone, use a second Dialogue Runner. The Background Chatter sample does this.
Adding Presenters
The Dialogue Runner can’t show anything until it has Presenters. Most games start with two: a Line Presenter for lines, and an Options Presenter for options. The Dialogue System prefab has both, along with a Line Advancer:
The Dialogue Runner only talks to Presenters in its Dialogue Presenters list. A Presenter that isn’t in the list is never used, even if it’s a child of the Dialogue Runner. The one exception is the Line Advancer, which adds itself to the list when the scene starts. In the Dialogue System prefab, the list holds the Line Presenter, the Options Presenter and the Line Advancer.

To add a Presenter of your own, click + under the list, and drag the GameObject with the Presenter on it into the new row. From code, set the Dialogue Runner’s DialoguePresenters property to a new list.
Line Presenter and Options Presenter explain how to set up each Presenter, change how text appears, and style the option buttons.
The Dialogue Runner’s settings
| Setting | What it does |
|---|---|
| Yarn Project | The compiled Yarn Project to run. |
| Variable Storage | Where your Yarn variables are kept. Leave it empty and the Dialogue Runner adds an In Memory Variable Storage when the game runs. See Variables and Storage. |
| Line Provider | Looks up the text for each line, including translations. Leave it empty and the Dialogue Runner adds a Built-in Localised Line Provider when the game runs. See Line and Asset Providers. |
| Saliency Strategy | How the Dialogue Runner chooses between the nodes in a node group, and the lines in a line group. See Saliency and Storylets. |
| Dialogue Presenters | The Dialogue Presenters that show your dialogue. |
| Verbose Logging | Prints details of what the Dialogue Runner is doing to the Console, every time it enters a node and more, for tracking down problems. Off by default. |
| Start Automatically | Starts dialogue from Start Node when the scene starts, after waiting one frame. Off by default. |
| Start Node | The node to start from when Start Automatically is on. Only shown when it’s on. Defaults to Start. |
The settings for options are described below.
Starting and stopping dialogue
Turn on Start Automatically and the dialogue starts on its own when the scene starts, from the node set in Start Node.
Otherwise, start it from your own code, for example when the player talks to a character:
using UnityEngine;
using Yarn.Unity;
public class Rosa : MonoBehaviour
{
[SerializeField] DialogueRunner dialogueRunner;
public async YarnTask TalkToRosa()
{
await dialogueRunner.RunDialogue("Lighthouse");
}
}await RunDialogue() with the name of the node to start from, for example when the player walks up to Rosa and presses a button. Code after the await runs once the whole conversation has ended.RunDialogue(nodeName)starts from the node you name, and finishes once the whole conversation has ended. You always have to name a node, because Start Node is only used by Start Automatically.Stop()ends the dialogue. It’s async too, and finishes once the Presenters have finished with the dialogue.IsDialogueRunningistruewhile dialogue is running. Use it to stop the player walking off mid-conversation.
To do something when a conversation ends, put it after the await:
public async YarnTask TalkToRosa()
{
player.canMove = false;
await dialogueRunner.RunDialogue("Lighthouse");
player.canMove = true;
}RunDialogue() while dialogue is already running, the Dialogue Runner logs an error and doesn’t start the new node. To end the first conversation, await dialogueRunner.Stop() before starting the new one.Starting dialogue from a UnityEvent
A UnityEvent, like a button’s On Click, can’t call a method that returns a task, which rules out RunDialogue(). Use StartDialogue(nodeName) there instead. It starts the dialogue and returns straight away, without waiting for the conversation to end. StartDialogue() is marked obsolete, and Unity shows a warning if you call it from code, because code should use RunDialogue(). It’s still there for UnityEvents.
Choosing a node from your own scripts
To get the same node dropdown as Start Node on your own scripts, add the [YarnNode] attribute to a string field, and name the field that holds the Yarn Project:
using Yarn.Unity;
using Yarn.Unity.Attributes;
public YarnProject project;
[YarnNode(nameof(project))]
public string startAt;The dropdown lists the project’s nodes in alphabetical order. To list only some of them, add a filter:
[YarnNode(nameof(project), filter: "Shop")]
public string shopNode;
[YarnNode(nameof(project), filterType: YarnNodeFilter.StartsWith, filter: "Intro_")]
public string introNode;
[YarnNode(nameof(project), filterHeader: "tags", filter: "chapter2")]
public string chapterNode;| Setting | What it does |
|---|---|
filter | The text to look for. |
filterType | YarnNodeFilter.Contains (the default), StartsWith, EndsWith, or MatchesRegex for a regular expression. The first three ignore upper and lower case. MatchesRegex doesn’t. |
filterHeader | Which header to look in. The default is title, the node’s name. Use tags, color, or any header your nodes have. |
Reacting to dialogue
The Dialogue Runner doesn’t have events to connect in the Inspector. Your code finds out what’s happening in two ways:
- To know when a conversation has ended,
awaitRunDialogue(), as shown above. - To know about everything else, write a small Presenter and add it to the Dialogue Runner’s Dialogue Presenters. The Dialogue Runner calls its methods as the dialogue runs, and you only write the ones you need.
| Presenter method | When it’s called |
|---|---|
OnDialogueStartedAsync(token) | Dialogue has started. |
OnDialogueCompleteAsync(token) | Dialogue has ended, either at the end of the dialogue or because Stop() was called. |
OnNodeEnter(nodeName, token) | The Dialogue Runner has entered a node. |
OnNodeExit(nodeName, token) | The Dialogue Runner has left a node. |
RunCommand(command, token) | The dialogue has reached a Command, whether or not anything handles it. |
For example, this Presenter stops the player moving while they’re in any conversation, however it was started:
using System.Threading;
using UnityEngine;
using Yarn.Unity;
public class PlayerLock : DialoguePresenterBase
{
[SerializeField] Player player;
public override YarnTask OnDialogueStartedAsync(CancellationToken token)
{
player.canMove = false;
return YarnTask.CompletedTask;
}
public override YarnTask OnDialogueCompleteAsync(CancellationToken token)
{
player.canMove = true;
return YarnTask.CompletedTask;
}
}Add the component to a GameObject, and drag it into the Dialogue Runner’s Dialogue Presenters list. You can also add it from code with dialogueRunner.AddPresenter().
Encountered undispatched command. If it hasn’t, the message is the error The command dispatcher has not been configured to handle the Command. A misspelt Command name is skipped in the same way. Check the Console if a Command doesn’t seem to do anything. To handle Commands yourself, write a Presenter with RunCommand().How it works with Presenters
When the Dialogue Runner reaches a line, it gives the line to every Presenter in its list at the same time. It waits until all of them have finished with it, then moves on. A Line Presenter and a Voice Over Presenter can work on the same line, and the Dialogue Runner continues only once the text has been dismissed and the clip has finished.
When it reaches a set of options, it gives them to every Presenter in the same way, and uses the first option any of them picks.
The Line Advancer tells the Dialogue Runner to move on when the player presses a button. If you’re building your own controls, call these yourself:
RequestHurryUpContent()asks the current content to finish appearing at once, such as by skipping a line’s typing effect or making options appear without fading in. A line stays on screen.RequestNextContent()asks the Presenters to finish with the current line and move on.
Both also reach a Command that’s running, if it takes a cancellation token. The older RequestHurryUpLine(), RequestHurryUpOption() and RequestNextLine() still work, but they’re obsolete.
Options
These settings change how options work.
| Setting | Default | What it does |
|---|---|---|
| Run Selected Option As Line | Off | After the player picks an option, show its text as a line of dialogue before continuing. In the Behaviour section, under Start Automatically. |
| Allow Option Fallthrough | On | If none of your Presenters picks an option, carry on with the dialogue after the options. Below the Behaviour section. |
Saving and loading
The Dialogue Runner can save your Yarn variables to a file in Unity’s persistent data path, and load them back:
dialogueRunner.SaveStateToPersistentStorage("dialogue_save.json");
dialogueRunner.LoadStateFromPersistentStorage("dialogue_save.json");Both return true if they worked. They save and load the variables in the Dialogue Runner’s Variable Storage. See Variables and Storage for other ways to save your variables along with the rest of your game.