Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
In Yarn Spinner, all of your dialogue is stored in .yarn
files. Yarn files are just plain text files, which you can edit in any text editor.
Yarn Spinner files contain nodes. Nodes are where you put your dialogue. You can have as many nodes as you link in a file. Nodes are used to separate out parts of the story, and make it easier to manage longer stories and branching.
Each node has, at the very minimum, a collection of headers, and a body. All nodes have at least one header, which is the title. The title is the name of the node, and the body contains the Yarn script that contains your game's dialogue.
The title of a node is important, because your game uses node titles to tell Yarn Spinner which node to start running. You also use the title of a node when you want to jump to another node.
Node titles are not shown to the player.
Node titles must start with a letter, and can contain letters, numbers and underscores.
So FirstNode, First_Node and Node1 valid, but First Node and 1stNode are not.
Node names cannot contain a . (period).
Node names were able to contain a period in Yarn Spinner 1, and if your Yarn Spinner 1 .yarn
scripts have periods in the node names, then the upgrader script will translate them (and all jumps and options related) to use a _
(underscore) instead.
If you're using a text editor to write Yarn scripts, you'll need to write the node's header.
If you're using a graphical editor to write Yarn scripts, like Yarn Editor, it will handle this for you, and you can skip this section.
The plain-text version of a Yarn node looks like this:
In this example, the node's title is Node_Title
, which is set on the first line in the title
header. You can also add any other headers that you want.
Node headers can contain any number of lines with the structure key: value
. This can be used to store additional information, such as the location the conversation is taking place.
The ---
marker indicates where the body begins. After this point, you can put all of your Yarn script.
The ===
marker indicates where the node ends; after this point, you can begin another node.
The body of a node is made up of three different kinds of content: lines, commands, and options.
When you write Yarn Spinner dialogue, just about every line of text that you write in a node is a line. When a node is run, it runs each line, one at a time, and sends it to your game.
A line of dialogue is just the thing you want some entity or character to say, usually beginning with the name of the entity speaking.
For example, consider the following Yarn code from Night in the Woods:
When this code is run in the game, it looks like this:
Yarn Spinner sends each of these lines, one at a time, to the game. The game is responsible for taking the text, and presenting it to the player; in the case of Night in the Woods, this means drawing the speech bubble, animating each letter in, and waiting for the user to press a key to advance to the next line.
Lines of dialogue can contain just about any text, except for some special characters that Yarn Spinner uses to add extra information to a line.
If there is a set of characters without spaces before a colon (:) at the beginning of the line, Yarn Spinner will mark that as the name of the character. This information will then be passed to your game, so that you can change the way that lines are shown based on the character who's saying them. For example:
When you want to let the player decide what to say, you use an option. Options let you show multiple potential lines of dialogue to the player, and let the player select one.
Options are marked with a ->
symbol. You write as many options as you'd like the player to see, and the player chooses one of them. The content of the option is like any other line of dialogue.
For example, consider the following code:
In this example, the line "Hi there! What do you feel like doing today?" will run. The player will then be given the choice to say either "I want to go swimming", or "I'd prefer to go hiking".
Shortcut options can have their own lines, which are run when the option is selected. If a different option is selected, they won't run. To write this, indent the lines that belong to a shortcut option.
In the following code, different lines will run based on which of the two shortcut options are selected.
This script will start with the line, "Hi there! What do you feel like doing today?". The player then has the choice of saying either "I want to go swimming", or "I'd prefer to go hiking". Depending on their choice, either the line "Okay, let's go swimming" or "Cool, we'll go hiking then". Finally, no matter what was selected, the line "Sounds good!" will run.
In addition to containing lines, options can also contain other options.
You can nest options as much as you like. However, this can get a bit challenging to read. It's often a good idea to use the <<jump>>
command to jump to a different node:
Separating dialogue segments into nodes can for neater files that are easier to edit as they grow.
Sometimes it makes sense for the options presented or the outcomes of selecting different options to vary based on other things the player has done or said up until this point. This requires the use of logic and variables, which we'll discuss in the next section.
Learn about writing with the Yarn Spinner Visual Studio Code Extension.
The preferred way of writing your Yarn Spinner code is with the official Yarn Spinner Visual Studio Code Extension.
The official extension adds syntax highlight to VS Code's text editor, as well as a graph view that displays the nodes, and relationships between the nodes.
If you've never used to Visual Studio Code before, head to their official website and install it for your operating system and platform, and then continue to Installing the Extension.
Visual Studio Code is a powerful, flexible, open source code editor for Windows, macOS, and Linux. It supports extensions, which allow it to perform a wide range of useful tasks. The Yarn Spinner Extension is one of these.
Yarn Spinner is a tool for writers. In this section, you'll the syntax of Yarn, how to write Yarn scripts for use in your game. You'll also learn how to use the various tools that are available for creating your content.
You'll need an editor before you can write Yarn scripts, so we recommend checking out before going too far.
With the Yarn Spinner Visual Studio Code Extension installed, you can make new Yarn files, and edit existing ones, right inside the VS Code editor.
You can use the File menu -> New file command to make a new empty file. Simply save the file with a .yarn extension to activate the Yarn Spinner Extension features.
You can open any existing .yarn file, or collection of .yarn files, using VS Code:
With a .yarn file open, you can edit it in the text editor. The chosen .yarn file(s) will open, and you'll be able to work with them, edit them, and save them as needed:
You can show and hide the Graph View. If you click the "Show Graph" button, in the top right-hand corner, the Graph View will appear:
You can use the "Add Node" button to add new nodes. New nodes will appear in the Graph View, and in the text editor:
Links (for example, using the jump commands) between nodes will be visualised in the Graph View. You can use the edit button on a node in the Graph View to jump to the appropriate location in the text editor, and you can rearrange the nodes visually in the Graph View for ease of understanding the relationships between areas of your script:
You can also use the "Jump to Node" button to move to a specific node in the Graph View. This allows you to easily move between areas of your text script. Nodes in the graph view can be rearranged for convenience; this won't impact the text version of the yarn script other than updating the position (below the node title).
Learn what you need to to get started with Yarn Spinner 2.0
is the friendly tool for writing dialogue in games. It's easy for writers to use, and has powerful features for programmers.
Yarn Spinner is a dialogue system that lets you write interactive conversations in a simple, screenplay-like format, which can be loaded into your game and run.
When a conversation is running, Yarn Spinner sends your game lines of dialogue to show, options to let the player choose from, and commands to make things happen in your scene.
Yarn Spinner has been used in a number of critically acclaimed games, including , , , and many more.
It's free to download and use for free and commercial games, and is open source under the terms of the .
Yarn Spinner 2.0 is our latest release!
Yarn Spinner is made up of two things:
Yarn files that contain the script for your game, and;
The Yarn Spinner framework for your chosen game engine or method of delivery.
To use Yarn Spinner 2.0, you will need:
An editor to write and edit .yarn scripts with. We recommend using the official Yarn Spinner Visual Studio Code extension, together with Visual Studio Code.
A copy of Yarn Spinner for your game engine of choice. Currently, Yarn Spinner supports Unity, so you'll need Yarn Spinner Unity.
A .yarn script (or a few of them). These will be the narrative, or bits of narrative, that Yarn Spinner uses to display and deliver your dialogue.
Yarn Spinner currently only officially supports Unity. There are community projects for other game engines, and we're officially working on more. Stay tuned for updates.
If you're already familiar with VS Code and VS Code extensions, you can just install the extension secretlab.yarn-spinner
and you'll be ready to go.
Once you've got Visual Studio Code (often abbreviated to "VS Code", or "Code") installed on your system, you'll want to install the Yarn Spinner extension. To install the Yarn Spinner Extension:
Launch Visual Studio Code.
Open the Extensions view. To do this, select the blocks symbol from the left-hand sidebar, or press Command+Shift+K on macOS, or Control+Shift+X on Windows or Linux.
Search for the Yarn Spinner Extension. With the Extensions view open, type "Yarn Spinner" into the search field.
Install the Extension. Once the results have loaded, click "Install" next to the Secret Lab-provided Yarn Spinner Extension.
That's all you need to do to install the extension! You're ready to write and edit Yarn scripts with Visual Studio Code.
This documentation is still in active development. If you see an issue, please .
This documentation is for Yarn Spinner 2.0. There are not equivalents for all the documentation that was present for Yarn Spinner 1.0, and certain pages are empty or have not yet been finished. You can find the old Yarn Spinner 1.0 documentation , if you still need it.
You can find details on installing VS Code and the official Yarn Spinner Visual Studio Code Extension here:
You can learn more about Yarn Spinner Unity here:
You can learn more about writing in Yarn here:
You can also learn more about the various , as well as here, if you'd like.
If you'd like to join the wider Yarn Spinner community, we also have a .
The Yarn language is a full programming language, which means it has support for writing code that let you control how the dialogue in your game works. In this section, you'll learn how to use variables to control your dialogue.
Variables store information. Variables can store one of three types of information: numbers, strings, and booleans.
Type | Possible Values | Examples |
---|---|---|
Every variable has a name. In Yarn Spinner, all variable names start with a dollar sign ($
).
You put information into a variable by using the <<set>>
command. For example, the following code puts a string, "Hello, Yarn!"
, into a variable called $greeting
:
As with node titles, variable names must not contain spaces. They must be made up of only letters, numbers and underscores, and the first character must be a letter.
Each variable can only store one type of value. Variables can change their value at any time, but they can never change their type.
For example, the following code will work:
This works because while the value of each of the variable changes, the type doesn't. However, the following code will not work:
Starting with Yarn Spinner 2.0, variables are never null
. All variables are required to have a value.
You can work with the values inside variables. For example, numbers can be multiplied, strings can be added together, and boolean values can have logical operations (like and and or) applied to them. When values are used together like this, it's called an expression.
An expression needs to be a single type. You can't work with values of different types in a single expression. For example, the following code will not work:
Yarn Spinner provides built-in functions for converting between certain types:
The string
function converts values of any type into a string.
The number
function converts values of any type into a number (if it can be interpreted as one.)
The bool
function converts values of any type into a boolean value (if it can be interpreted as one.)
To show the contents of a variable, you put it inside braces ({ }
) inside a line. The value of that variable will appear in its place.
For example:
Yarn Spinner doesn’t manage the storage of information in variables itself. Instead, your game provides a variable storage object to Yarn Spinner before you start running dialogue.
When Yarn Spinner needs to know the value of a variable, it will ask the variable storage object you’ve given it. When Yarn Spinner wants to set the value of a variable, it will provide the value and the name of the variable. In this way, your game has control over how data is stored.
The specifics of how variables need to be stored will vary depending on what game engine you're using Yarn Spinner in. To learn more about variable storage in Unity, see Variable Storage.
Number
Any whole or decimal number
1, 2.5, 3468900, -500
String
Any sequence of letters, numbers and other characters, enclosed in quotes.
"Hello", "✓", "A whole sentence."
Boolean
Either the value true or the value false.
true, false
if
statementsIn addition to storing information, variables are useful for controlling what's shown to the player. To do this, you use if
statements.
An if
statement allows you to control whether a collection of content is shown or not. When you write an if
statement, you provide an expression, which is checked; if that expression evaluates to a "true" value, then all of the content in between the <<if>>
and <<endif>>
statements are run.
For example, consider the following code:
This example will set a variable, $gold_amount
, to 5. It will then show the line "I'd like to buy a pie!", and before it continues, it will check to see if $gold_amount
is less than 10. If that's the case (which it will be!), the line "Well, you can't afford one!" will run.
elseif
and else
You can use the elseif
and else
statements to handle different situations in an if
statement.
An elseif
statement has an expression that gets checked if the if
statement, or any previous elseif
statements, don't run.
An else
statement doesn't have an expression, and runs
For example:
This script will show different lines depending on the value of $gold_amount
. The checks are done from top to bottom, which means that in order for an elseif
or else
to run, all of the checks above it have to have failed.
If it's less than 10, the line "Well, you can't afford one!" will run.
Otherwise, if it's less than 15, the line "You can almost afford one!" will run.
Otherwise, the line "Here you go!" will run.
The expression used in an if
and elseif
statement must result in a boolean value (that is, true or false.) For exame,<<if 1>>
isn't allowed, but <<if 1 == 1>>
is.
When presenting options to the player, you may want to make some options not available. You can do this by adding a condition to the option.
For example, if you have a variable that tracks your player's "reputation points", called $reputation
, you might want to make certain options only available if the value of $reputation
is high enough.
Conditions on options are done by adding an if
statement to the end of the option. They look like this:
When Yarn Spinner runs this collection of options, it will check the expression inside the if
statement. If the expression is false
, then the option will be marked as unavailable.
Yarn Spinner always delivers every option in an option group to the game; it's up to the game to decide what to do with options that are marked as unavailable.
For example, an unavailable option might be shown to the user, but not selectable, so that the user can see that they could have been able to say that if circumstances had been different.
Now that you know how to work with nodes, lines, options and variables, there's one last part of the Yarn language to learn about: commands.
In Yarn Spinner, you can send instructions to your game through commands. Commands look like this:
Commands are sent to your game's Dialogue Runner, just like lines and options are. Commands are not shown to the player directly; instead, they're used for things like stage directions.
Yarn Spinner comes with some built-in commands; however, to get the most usefulness out of them, you'll want to define your own custom commands that make your game do what you need to.
There are two built-in commands in Yarn Spinner: wait
, and stop
.
wait
The wait
command pauses the dialogue for a specified number of seconds, and then resumes. You can use integers (whole numbers), or decimals.
stop
The stop
command immediately ends the dialogue, as though the game had reached the end of a node. Use this if you need to leave a conversation in the middle of an if
statement, or a shortcut option.
You can create your own commands, so that your scripts can . For more information on how to create them in Unity games, see Creating Commands and Functions.
Upgrading your Yarn Spinner 1.x scripts to Yarn Spinner 2.x is easy.
The Yarn Spinner Console (ysc
) can upgrade your older .yarn
scripts to the latest syntax.
The Yarn Spinner Console (ysc
) is in heavy development, and is likely to have its own complete section here, in the documentation, before long. Until then, find further initial documentation via its GitHub project.
To upgrade your scripts:
Install the version of Yarn Spinner Console that matches your version of Yarn Spinner. You can do this via the Yarn Spinner Console GitHub Project. Choose Releases in the sidebar, and download the appropriate binary for your platform. If you just want the latest release, you can find it here.
Run the upgrader on your scripts. To upgrade, you must run ysc
on your command-line/terminal with the upgrade
parameter and a path to a yarn file:
You can also run the upgrade on multiple scripts at once. To do this, you can pass in as many .yarn
files as you want:
By default, ysc
will replace the existing .yarn
files you've passed in, as part of the upgrade. If you don't want it to do this, either make sure you have a backup, or pass in the --output-directory
option, after the upgrade
parameter. For example:
Markup allows you to add attributes into your text, like [a]hello[/a]
. These attributes can be used by your game to do things like change the formatting of the text, add animations, and more.
When text is parsed, the tags are removed from the text, and you receive information about the range of the plain text that the attributes apply to.
Attributes apply to ranges of text:
Yarn Spinner will take this text, and produce two things: the plain text, and a collection of attributes. The plain text is the text without any markers; in this example it will be:
Attributes represent ranges of the plain text that have additional information. They contain a position, a length, and their name, as well as their properties.
In this example, a single attribute will be generated, with a position of 4, a length of 5, and a name of "wave".
Attributes are opened like [this]
, and closed like [/this]
.
Attributes can overlap:
You can put multiple attributes inside each other. For example:
You can close an attribute in any order you like. For example, this has the same meaning as the previous example:
Attributes can self-close:
A self-closing attribute has a length of zero.
The marker [/]
is the close-all marker. It closes all currently open attributes. For example:
Attributes can have properties:
This attribute 'wave' has a property called 'size', which has an integer value of 2.
Attributes can have short-hand properies, like so:
This is the same as saying this:
This attribute 'wave' has a property called 'wave', which has an integer value of 2. The name of the attribute is taken from the first property.
Properties can be any of the following types:
Integers
Floats
'true' or 'false'
Strings
Single words without quote marks are parsed as strings. For example, the two following lines are identical:
If a self-closing attribute has white-space before it, or it's at the start of the line, then it will trim a single whitespace after it. This means that the following text produces a plain text of "A B":
If you don't want to trim whitespace, add a property trimwhitespace
, set to false
:
You may want to show text containing the [
and ]
characters to your player. To prevent the markup parser from treating as special characters, you can escape them. Text that has been escaped will be treated as plain text, and will not be interpreted by the parser.
There are two ways to escape your markup: escaping single characters, and using the nomarkup
attribute.
[
and ]
charactersIf you need to escape a single square bracket character, put a backslash \
in front of it:
This will appear to the player as:
The backslash will not appear in the text.
If you need to show a blackslash in your text, use two blackslashes:
This will appear as:
nomarkup
AttributeIf you want to escape a longer run of text, or if you have many square brackets, escaping a single character at a time can be cumbersome. In these cases, you may want to escape an entire region of text, using the nomarkup
attribute. This attribute makes the parser ignore any markup characters inside it.
If you want to include characters like [
and ]
, wrap them in the nomarkup
attribute:
This will appear as:
character
AttributeThe character
attribute is used to mark the part of the line that identifies the character that's speaking.
Yarn Spinner will attempt to add this character for you, by looking for character names in lines that look like this:
The markup parser will mark everything from the start of the line up to the first :
(and any trailing whitespace after it) with the character
attribute. This attribute has a property, name
, which contains the text from the start of the line up to the :
. If a :
isn't present, or a character
attribute has been added in markup, it won't be added.
This means that the example above is treated the same as this:
You can use this to trim out the character names from lines in your game.
Certain attributes in Yarn Spinner's markup are "replacement" markers, which Yarn Spinner uses to insert or replace text based on the value of a variable. There are three built-in replacement markers:
The select
marker uses the value of a variable to choose an outcome.
The plural
marker uses the value of a number to decide on the plural class for that number.
The ordinal
marker uses the value of a number to decide on the ordinal class for that number.
All three of these markers have a property called value
, and use this to decide what text should be used in the line.
select
The select
marker is the simplest of the built-in replacement markers. It takes the value of the value
property, and uses that to choose a replacement.
It's especially useful for when you need to insert a gendered pronoun in a line:
plural
and ordinal
The plural
and ordinal
markers take a number in its value
property, and use that to determine the plural or ordinal number class of that value.
Different languages have different rules for how numbers are pluralised.
In many languages, the term you use to refer to a thing depends on the the number of that thing. This is known as a plural class: in English, you can have one apple, but many apples, and you have have one mouse, but many mice.
However, the rules vary significantly across different languages. English has two: "single", and "other". However, for example, Polish has multiple.
In English, you say "one apple, two apples, five apples".
In Polish, you say "jedno jabłko, dwa jabłka, pięć jabłek".
Notice how the Polish word for "apple", "jabłko", takes multiple forms as the number changes, whereas it takes two forms in English.
In Yarn Spinner, individual lines are replaced depending on the user's locale, but the logic surround them is not. This means that, if you want to be able to translate your game into multiple languages, you can't write Yarn code like this:
If you did it this way, the logic would only work for languages that have the same rules for plurals as English. (There are several of them that do, but far more that don't.)
Complicating this further, there are two main kinds of plural classes: cardinal plural classes, and ordinal plural classes.
Cardinal plural classes are the kind we just saw (for example, "one apple, two apples").
Ordinal plural classes refer to the positioning of a thing; in English, ordinal numbers are things like "1st, 2nd, 3rd."
As with cardinal plural classes, different languages have different ordinal plural classes.
plural
and ordinal
Yarn Spinner is able to take a number and the user's current locale, and determine the correct cardinal or ordinal plural class of that number, for that locale. You can then use the plural class to decide on what text to show.
plural
and ordinal
have a property called value
, just like select
. They then have a property for each of the current locale's plural classes. These can be:
one
two
few
many
other
The two markers differ based on what kind of plural class they work with:
plural
selects a number's cardinal plural class.
ordinal
selects a number's ordinal plural class.
Not every language uses every category; for example, English only uses "one" and "other" for cardinal plural classes.
For each of these properties, you provide the text that should appear.
For example:
You can include the actual value in the resulting text by using the %
character. This character will be replaced with the value provided to the value
property:
The ordinal
marker works similarly, but uses the ordinal plural class:
A function is a block of code that provides a value to your Yarn scripts, which you can use in , or store in .
In Yarn Spinner scripts, functions perform two main kinds of task:
Functions let you get values that change over time, or that depend on other values. For example, the random
function returns a different random number every time you call it.
Functions let you get data from your game back into your scripts.
You call a function inside an expression. For example:
Yarn Spinner comes with several built-in functions for you to use.
random()
random
returns a random number between 0 and 1 each time you call it.
random_range(number a, number b)
random_range
returns a random integer between a
and b
, inclusive.
dice(number sides)
dice
returns a random integer between 1 and sides
, inclusive.
For example, dice(6)
returns a number between 1 and 6, just like rolling a six-sided die.
round(number n)
round
rounds n
to the nearest integer.
round_places(number n, number places)
round_places
rounds n
to the nearest number with places
decimal points.
floor(number n)
floor
rounds n
down to the nearest integer, towards negative infinity.
ceil(number n)
ceil
rounds n
up to the nearest integer, towards positive infinity.
inc(number n)
inc
rounds n
up to the nearest integer. If n
is already an integer, inc
returns n+1
.
dec(number n)
inc
rounds n
down to the nearest integer. If n
is already an integer, inc
returns n-1
.
decimal(number n)
decimal
returns the decimal portion of n
. This will always be a number between 0 and 1. For example, decimal(4.51)
will return 0.51
.
int(number n)
int
rounds n
down to the nearest integer, towards zero.
This is different to floor
, because floor
rounds to negative infinity.
You can define your own custom functions in Yarn Spinner. For more information, see .
Functions are not intended to be a way for you to send instructions to your game. For that purpose, you should use .
In particular, functions are not guaranteed to be called in the same order as they appear in your code, or even be called at all if Yarn Spinner believes the result can be cached. As much as possible, custom functions should be , and have no side effects besides returning a value based on parameters.
Yarn Spinner for Unity is the set of components and scripts that make Yarn Spinner work inside a Unity project.
In this section, you’ll learn how to install, set up, and work with Yarn Spinner for Unity.
Yarn Spinner for Unity works with Unity version 2019.4 and later.
Learn about Yarn scripts, which are the assets that contain the dialogue you write.
A Yarn script is a text file containing your dialogue.
Yarn scripts need to be added to a Yarn Project in order to be used in your game.
To create a new Yarn script in Unity, follow these steps:
Open the Assets menu, and choose Yarn Spinner -> Yarn Script.
Unity will create a new file. Type in a name for the file, and press return.
The new file that you've just created will contain a single node, which has the same name as the file.
Creating a Yarn Script in Unity is exactly the same as creating a .yarn
file externally (i.e. in macOS Finder or Windows Explorer), and dragging it into the Assets folder of your Unity project, or directly into the Project pane (where the new Yarn Script we created through the process above appeared) in Unity.
To edit a Yarn script, double-click it in Unity. The file will open in your editor. When you save your changes and return to Unity, it will be re-compiled.
You can learn about our recommended editor, Visual Studio Code with the official Yarn Spinner Extension at: Editing with VS Code.
Quickly get started with a simple scene.
Want to use Yarn Spinner in a new scene right away? Follow these steps.
Create a new empty Unity project, by following the instructions in the Unity manual.
Install Yarn Spinner into the project, by following the instructions in Installation.
Add the Dialogue System prefab to the scene:
In the Project pane, scroll down to the Yarn Spinner folder. You'll find it in the Packages section.
Inside the Yarn Spinner folder, open the Prefabs folder, and locate the Dialogue System prefab.
Drag the Dialogue System into your scene.
Create a new Yarn script, by opening the Assets menu and choosing Create -> Yarn Spinner -> Yarn Script. Name the new file HelloYarn
.
Open the new Yarn script by double-clicking it.
Select all of the text in the file, and delete it.
Copy the text below, and paste it into the file.
You can learn about our recommended editor, Visual Studio Code with the official Yarn Spinner Extension at: Editing with VS Code.
Save the file and return to Unity.
Create a new Yarn Project that uses this script, by selecting the HelloYarn
file, and clicking the Create New Yarn Project button in the Inspector. This will create a new Yarn Project called Project
.
Attach the Yarn Project to the Dialogue Runner, by selecting the Dialogue Runner in the Hierarchy, and dragging the Project
into the Yarn Project field.
Play the game by clicking the Play button at the top of the window. Your dialogue will appear!
This tutorial shows you how to install Yarn Spinner for Unity, the Unity integration for running Yarn and Yarn Spinner scripts in your Unity-based games.
There are two ways to install Yarn Spinner for Unity: via the Package Manager, and via a .unitypackage
file.
We recommend installing it via the Package Manager, because of a few reasons: it's easier to update to new versions of Yarn Spinner as they become available, it doesn't get embedded in the source code of your game, and you have more control over what gets added to your project.
You can install the Yarn Spinner package into your project using the Package Manager window in Unity.
Yarn Spinner is available via the . This is the simplest way to install Yarn Spinner, and makes it easy to keep it up to date.
In order to follow the instructions in this section, your project needs to be using Unity 2020.1 or higher. If your project is using an earlier version of Unity, we recommend installing Yarn Spinner from Git.
Before you can install Yarn Spinner from OpenUPM, you first need to configure your project so that it knows where to get the package from.
In Unity, open the Edit menu, and choose Project Settings.
In the list of sections at the left hand side of the window, select Package Manager.
This window is where you tell Unity about where to find packages that come from registries besides Unity's built-in one.
In the Name field, type OpenUPM
.
In the URL field, type https://package.openupm.com
.
In the Scopes field, type dev.yarnspinner
.
Click Save.
When you're done, the settings window should look like this:
You can now install Yarn Spinner itself.
Open the Window menu, and choose Package Manager.
In the toolbar, click Packages: In Project, and choose My Registries.
Yarn Spinner will appear in the list. Select it, and click Install.
Yarn Spinner will download and install into your project.
You can verify that everything is imported succesfully by looking for Yarn Spinner under Packages, in the Project pane.
As an alternative to downloading Yarn Spinner from OpenUPM, you can install Yarn Spinner by downloading the package directly from GitHub, where the project's source code is stored.
Where possible, we recommend installing Yarn Spinner from OpenUPM rather than GitHub, because it's easier to update to new versions.
To install Yarn Spinner from GitHub, follow these instructions.
In Unity, open the Window menu, and choose Package Manager.
Click the +
button, and choose "Add package from git URL".
In the text field that appears, enter the following URL: https://github.com/YarnSpinnerTool/YarnSpinner-Unity.git
.
Be sure to type the URL exactly as it appears in this document, or the installation won't work.
The project will download and install. This might take a moment.
If you don't want to install Yarn Spinner as a package, you can download it as a .unitypackage
file, and extract it into your project.
This approach works in all versions of Unity. However, because it installs the Yarn Spinner files directly into your project's Assets folder and doesn't do any versioning, updating to a newer version of Yarn Spinner is more complicated. Where possible, we recommend installing Yarn Spinner from OpenUPM or from Git.
To download and install the file, follow these steps:
In Unity, open the Window menu, and choose Package Manager.
Locate Text Mesh Pro in the list, and select it.
Click the Install button to install Text Mesh Pro. This package is required for Yarn Spinner to work.
Download the .unitypackage
for that release.
Open the .unitypackage
. Unity will ask which files you want to add. In almost every case, you'll want to import all files.
Click Import.
Once you've installed Yarn Spinner, you're ready to start using it!
Next, open your browser, and go to the of Yarn Spinner for Unity on GitHub.
There are two important kinds of files you'll use when working with Yarn Spinner for Unity:
Yarn Scripts are files that contain your written dialogue.
Yarn Projects are files that link all of your scripts together, and are used by the Dialogue Runner.
Learn about the Unity components that you use when working with Yarn Spinner for Unity.
Yarn Spinner for Unity is made up of a number of components. The most important of these are the Dialogue Runner, which loads and runs your scripts, and the Dialogue Views that show content to your player.
In this section, you'll learn about how to work with each of these.
Learn about Yarn Projects, which group your scripts together for use in a Dialogue Runner.
A Yarn Project is a file that links multiple Yarn scripts together. Yarn projects are how Dialogue Runners work with your content.
To create a new Yarn Project, follow these steps:
Open the Assets menu, and choose Yarn Spinner -> Yarn Project.
Unity will create a new file. Type in a name for the file, and press return.
This new Yarn Project will be empty, and won't contain any references to other Yarn scripts yet.
On their own, a Yarn Project doesn't do anything. In order to be useful, you need to add Yarn scripts to it.
To add Yarn scripts to a Yarn Project, follow these steps:
Select the Yarn Project in the Project Pane.
In the Inspector, open the Source Scripts property at the top of the pane.
Drag the Yarn script you want to add into the Source Scripts list.
Click Apply at the bottom of the pane.
As an alternative to creating an empty project and adding scripts to it, you can create a new Yarn Project from a script. To do this, follow these steps:
Select the Yarn script in the Project pane.
In the Inspector, click the Create New Yarn Project button.
Clicking this button does two things:
A new Yarn Project will be created next to the Yarn script.
The new Yarn Project will be set up to include the Yarn script you created it from in its list of source scripts.
A Yarn Project's inspector shows information about every variable that are used in the Yarn scripts. This section of the Inspector shows the name, type, description, and default value of each variable.
This information comes from the following locations:
All variables that have been declared in a Yarn script with a declare
statement
All variables that have been manually added to this Yarn project
All variables that are used, but don't have a declare
statement
Declaring a variable in a Yarn script by using a declare
statement, or by manually adding it to the variables list, allows you to ensure that the variable is of the type you expect it to be, and that it has a description that explains the intended purpose of the variable.
If you don't declare a variable, Yarn Spinner will attempt to figure the variable's type out based on how it's used, and won't be able to provide a description.
When you write a Yarn script, you write it in a specific human language. This is referred to as the 'base' language of the script. It's called the base language because it's the one you start with, and the one you translate into other languages.
Unless you change it to something else, Yarn Spinner will set the base language to your computer's current locale.
You can set the base language of a Yarn Project in the Inspector by changing the Base Language setting.
If you want to translate your scripts into another language, or if you want to associate each line with assets (like voice over audio clips), you create a new Localisation. To learn about this process, see Adding Localizations and Assets to Projects.
Yarn Projects are used by Dialogue Runners. When a Dialogue Runner is told to start running dialogue, it reads it from the Yarn Project it's been provided.
If you try to start a Dialogue Runner and it doesn't have a Yarn Project, or the Yarn Project doesn't have any Yarn scripts, or if any of the Yarn scripts contain an error, the Dialogue Runner won't be able to run.
Learn about the Dialogue Runner, which runs the contents of your Yarn Scripts and delivers lines, options and commands to your game.
The Dialogue Runner is the bridge between the dialogue that you've written in your Yarn scripts and the other components of your game. It's a component that's responsible for loading, running and managing the contents of a , and for delivering the content of your to the other parts of your game, such as your user interface.
Setting up a Dialogue Runner is the first step in adding dialogue to your game. To use a Dialogue Runner, you add it to a game object in your scene, connect it to , and provide it with a to run.
When you want to start running the dialogue in your game, you call the Dialogue Runner's method. When you do this, the Dialogue Runner will begin delivering lines, options and commands to its Dialogue Views.
The Dialogue Runner is designed to work with other components of Yarn Spinner for Unity:
The contents of your dialogue are delivered to your .
The values of are stored and retrieved using the Dialogue Runner's .
The content that users should see - that is, the text in their current language, voice over clips, and other asset - are retrieved using the Dialogue Runner's .
The bare-bones minimum that a Dialogue Runner needs in order to work is a Yarn Project and at least one Dialogue View. If you don't set up a Variable Storage or a Line Provider, the Dialogue Runner will use temporary placeholders.
Property | Description |
---|
Property | Description |
---|---|
Source Scripts
The list of Yarn Scripts that this Yarn Project uses.
Declarations
The list of variables that are declared in this Yarn Project, or in the Yarn Scripts that this project uses.
Base Language
The language that the Yarn Scripts are written in.
Localisations
A mapping of languages to string tables and associated assets. See Adding Localizations and Assets to Projects for more information.
Search All Assemblies
If this is turned on, Yarn Spinner will search for custom commands and functions in all of your project's code and packages.
If this is turned off, it will only search for them in the default assembly, and in the assemblies specified in Assemblies to Search.
By default, this is turned on.
Assemblies To Search
If Search All Assemblies is turned off, Yarn Spinner will search for commands and actions in the assemblies you specify in this list, as well as the default assembly.
This list will only appear if Search All Assemblies is turned off.
Use Addressable Assets
If this is turned on, the Yarn Project will configure itself to look for assets using the Addressable Assets system.
This checkbox will only appear if the Addressable Assets package is installed in your project.
Update Asset Addresses
When you click this button, all of the assets in the folders specified in the Languages to Source Assets list will have their address updated to match the line ID they refer to.
Export Strings as CSV
When you click this button, all of the lines in the Yarn Scripts that this project uses will be written to a .csv
file, which can be translated to other languages. See Adding Localizations and Assets to Projects for more information.
Update Existing Strings Files
When you click this button, all .csv
strings files that are configured in the Languages to Source Assets list will be updated with any lines that have been added, modified or deleted since the strings file was created. See Adding Localizations and Assets to Projects for more information.
Add Line Tags to Scripts
When you click this button, any line of dialogue in the Source Scripts list that doesn't have a #line:
tag will have one added. See Adding Localizations and Assets to Projects for more information.
Yarn Project |
Variable Storage |
Line Provider |
Dialogue Views |
Start Automatically |
Start Node | If Start Automatically is turned on, the Dialogue Runner will start running this node when the scene starts. (If your Yarn Project does not contain a node with this name, an error will be reported.) |
Automatically Continue Lines |
Run Selected Options as Lines | If this is turned on, when the user chooses an option, the Dialogue Runner will run the selected option as if it were a Line. |
Verbose Logging | If this is turned on, the Dialogue Runner will log information about the state of each line to the Console as it's run. |
On Node Start | A Unity Event that's fired when the Dialogue Runner begins running a new node. This may be fired multiple times during a dialogue run. |
On Node Complete | A Unity Event that's fired when the Dialogue Runner reaches the end of a node. This may be fired multiple times during a dialogue run. |
On Dialogue Complete | A Unity Event that's fired when the Dialogue Runner stops running dialogue. |
On Command |
Learn about Dialogue Views, which present dialogue content to the user.
A Dialogue View is a kind of component that receives content from a Dialogue Runner, and presents it to the player. Dialogue Views are how the player sees your game's lines of dialogue, and how they select choices in the dialogue.
A Dialogue Runner can have multiple Dialogue Views. For example, you might have one Dialogue View that's designed to display lines of dialogue, and another that's in charge of displaying options to the player.
Because every game's needs are different, a Dialogue View is designed to be extremely customisable. However, because there are common patterns of how games work with dialogue, Yarn Spinner for Unity comes with some pre-built Dialogue Views that handle common use cases.
This section discusses the pre-built Dialogue Views:
is a Dialogue View that displays a single line of dialogue in a text box that's inside a canvas, and shows a button that the user can click to proceed.
is a Dialogue View that displays a collection of options in a list.
The that this Dialogue Runner is running.
The to store and retrieve variable data from. If you do not set this, the Dialogue Runner will create an for you at runtime.
The to use to get user-facing content for each line. If you do not set this, the Dialogue Runner will create a for you at runtime.
The to send lines, options and commands to.
If this is turned on, the Dialogue Runner will start running the node named Start Node when the scene starts. If this is not turned on, you will need to call to start running.
If this is turned on, lines will automatically continue as soon as all Dialogue Views have finished presenting them. If this is turned off, the Dialogue Runner will wait for a Dialogue View to call to continue.
A Unity Event that's fired when a Command is encountered. This will only be called if no other part of the system has already handled the command, such as command handlers registered via or .
Learn about Line View, a Dialogue View that displays a single line of dialogue on a Canvas.
Line View is a Dialogue View that displays a single line of dialogue inside a Unity UI canvas. When the Dialogue Runner encounters a line in your Yarn Script, the Line View will display it, wait for the user to indicate they're done reading it, and then dismiss it.
Line View only displays lines, and doesn't display options. You can use an additional Dialogue View to handle these, like an Options List View or a custom Dialogue View of your own.
If a line contains a character's name at the start, Line View can be configured to show the name in a separate text view to the line text itself. If the Character Name Text property is connected to a TextMeshPro Text object, then the character's name will appear in this object.
If you don't attach a Text object to the Character Name Text property, you can choose to either show the character name as part of the line (that is, in the Line Text view), or don't show it all.
Line View can be configured to use visual effects when presenting lines.
You can choose to have the Line View fade in when a line appears, and fade out when the line is dismissed.
You can choose to have the text of the line appear, one letter at a time, with a "typewriter" effect.
You can control how the player can decide to proceed to the next line.
You can set up a Button, or any other Unity UI control, to call the OnContinueClicked method on this line.
You can also make the Line View continue to the next line when the user performs some input:
If you set the Continue Action Type to Key Code, you can select a key on the keyboard that will continue to the next line on press.
If you set the Continue Action Type to Input Action, you can create an Action from an input device (such as from a keyboard, gamepad, or other method).
If you set the Continue action Type to Input Action from Asset, you can attach an Action from an Input Actions asset that you've set up elsewhere.
If you want to use Input Actions, your project will need to be set up to use the new Unity Input System.
Property | Description |
---|---|
Canvas Group
The Canvas Group that the Line View will control. The Canvas Group will be made active when the Line View is displaying a line, and inactive when not displaying a line.
Line Text
A TextMeshPro Text object that the text of the line will be displayed in.
Use Fade Effect
If this is turned on, the Line View will fade the opacity of the Canvas Group from 0% to 100% opacity when lines appear, and fade back to 0% when lines are dismissed.
Fade In Time
The duration of the Fade effect when fading a new line in, in seconds. If this is zero, the line will appear immediately.
Fade Out Time
The duration of the Fade effect when fading a line out, in seconds. If this is zero, the line will disappear immediately.
Use Typewriter Effect
If this is turned on, the text of the line will appear one character at a time. This will take place after the Fade effect, if enabled.
On Character Typed
A Unity Event that's called every time the Typewriter effect displays new text.
Typewriter Effect Speed
The number of characters per second to display when performing a Typewrite effect. Larger values means that text will appear faster.
Character Name Text
A TextMeshPro Text object that will display the name of the character currently speaking the line.
Show Character Name In Line View
If this is turned on, lines that contain a character's name will display the name in the Line Text section. If it is turned off, character names will not be shown at all. This option is only available when Character Name Text is empty.
Continue Action Type
A drop-down list that selects how user input will be used to continue to the next line.
When set to None, the dialogue will not continue based on user input.
When set to Key Code, the dialogue will continue when the user presses the keyboard key specified in Continue Action Key Code.
When set to Input System Action, the dialogue will continue when the user performs the Action set up in Continue Action.
When set to Input System Action from Asset, the dialogue will continue when the user performs the Action specified by the Continue Action Reference field.
Continue Action Key Code
The keyboard key that the user should press to continue to the next line.
Continue Action
An Input Action that the user should perform to continue to the next line.
Continue Action Reference
An Input Action, stored inside an Input Actions asset, that the user should perform to continue to the next line.
Continue Button
A game object that will be made active when the line has finished appearing. This is intended to be used for controlling the appearance of a button that the user can interact with to continue to the next line.
Learn about Options List View, a Dialogue View that displays a list dialogue options.
Options List View is a Dialogue View that presents a list of options in a list.
When this view receives options from the Dialogue Runner, it creates an instance of the Option View prefab you specify in the Option View Prefab property, and adds it as a child of the options list view.
Options List View only displays options, and doesn't display lines. You can use an additional Dialogue View to handle these, like a Line View or a custom Dialogue View of your own.
Property | Description |
---|---|
Learn about Options View, a component used to display an option in an Options List View.
An Option View is an object that the Options List View uses when presenting options. When the Dialogue Runner delivers options to your game, Options List View will create an Option View for each option that could be selected.
When the Option View is pressed, the Options List View will notify the Dialogue Runner of the user's selection.
Property | Description |
---|---|
Canvas Group
The Canvas Group that the Options List View will control. The Canvas Group will be made active when the Options List View is displaying options, and inactive when not displaying options.
Option View Prefab
A prefab containing an Option View. The Options List View will create an instance of this prefab for each option that needs to be displayed.
Last Line Text
A TextMeshPro Text object that will display the text of the last line that appeared before options appeared. If this is not set, or no line has run before options are shown, then this property will not be used.
Fade Time
The time, in seconds, that the Options List View will take to fade in. If this is zero, the Options List View will appear immediately.
Show Unavailable Options
If this is turned on, then any options whose line condition has failed will still appear to the user, but they won't be selectable. If this is off, then these options will not appear at all.
Text
A TextMeshPro text object that will display the text of the line.
Show Character Name
If this is turned on, the Text component will show any character name present in the option. If this is turned off, the character name will not be included.
The In-Memory Variable Storage component is a Variable Storage component that stores all variables in memory. These variables are erased when the game stops.
The In-Memory Variable Storage component is intended to be a useful tool for getting started, and to be replaced with a custom variable storage that meets your game's needs.
However, if your game has no need to save and restore game state, then this class can be used in your final game, too.
Property | Description |
---|---|
Debug Text View
A Unity UI Text object that will display a summary of the variables that have been stored in this component. If this is not set, this property will not be used.
You can use this property to display a debug summary of your variables at run-time in your games.
Debug Variables
This area of the Inspector shows a summary of the variables. This works similarly to the Debug Text View property, but the summary is only ever shown in the Editor, and it doesn't require any setup.
Variable Storage components are responsible for storing and retrieving the values of variables in your Yarn scripts. When a Yarn script needs to get the value of a variable, it asks the Variable Storage for it; when a Yarn script sets the value of a variable, the Variable Storage is given the value.
Each game has different requirements for how variables are stored, which means that Yarn Spinner doesn't make any assumptions how the information is actually stored on disk. Instead, you can create your own custom Variable Storage script that implements the methods that Yarn Spinner needs.
If you don't have a game save system, you can use the In-Memory Variable Storage component. This is a simple Variable Storage component that's built into Yarn Spinner.
The In-Memory Variable Storage stores everything in memory; when the game ends, all variables that have been stored are erased.
If you don't connect a Variable Storage to your Dialogue Runner, it will create an In-Memory Variable Storage when the game starts, and use that.
Every game's data storage requirements are different. For this reason, Yarn Spinner is designed to make it straightforward to create your own custom component for managing how Yarn scripts store and load variables in ways that work with the other parts of your game.
Custom Variable Storage components are subclasses of the abstract class VariableStorageBehaviour
. To implement your own, you need to implement the following methods:
Property | Description |
---|---|
Text Language Code
The language that the Text Line Provider should use to fetch localised text for.
Line Providers are components that are responsible for taking the objects that the produces, and fetches the appropriate localised content for that line. Line Providers produce objects, which are sent to the Dialogue Runner's .
When a Yarn script runs, the Dialogue Runne produces Line objects. These objects contain information about the line, but not the text of the line itself. This is because it's the responsibility of the game to load the user-facing parts of the line, including the text of the line in the player's current language setting, as well as any other assets that may be needed to present the line (such as audio files for voiceover.)
Yarn Spinner comes with two built-in types of line providers:
is a Line Provider that fetches the text of a line, given a language to use.
is a Line Provider that fetches the text of a line as well as an , given languages to use.
If you don't set up a Line Provider for a Dialogue Runner, it will automatically create a Text Line Provider, and configure it to use the user's current language.
Text Language Code
The language that the Audio Line Provider should use to fetch localised text for.
Audio Language
The language that the Audio Line Provider should use to fetch localised audio clips for.
You can define your own commands, which allow the scripts you write in Yarn Spinner to control parts of the game that you've built.
In Unity, there are two ways to add new commands to Yarn Spinner: automatically, via the YarnCommand
attribute, or manually, using the DialogueRunner
's AddCommandHandler
method.
YarnCommand
attributeThe YarnCommand
attribute lets you expose methods in a MonoBehaviour
to Yarn Spinner.
When you add the YarnCommand
attribute to a method, you specify what name the command should have in Yarn scripts. You can then use that name as a command.
If the method is static, you call it directly. For example:
If you save this in a file called FadeCamera.cs
, you can run this code in your Yarn scripts like this:
If the method is not static
, you call it with the name of the game object you want the command to run on.
For example:
If you save this in a file called CharacterMovement.cs
, create a new game object called MyCharacter
, and attach the CharacterMovement
script to that game object, you can run this code in your Yarn scripts like this:
You can also use methods that take parameters. Yarn Spinner will take the parameters that you provide, and convert them to the appropriate type.
Methods that are used with YarnCommand
may take the following kinds of parameters:
Method parameters may be optional.
For example, consider this method:
This command could be called like this:
You can also add new commands directly to a Dialogue Runner, using the AddCommandHandler
method.
AddCommandHandler
takes two parameters: the name of the command as it should be used in Yarn Spinner, and a method to call when the function is run.
If you want to add a command using AddCommandHandler
that takes parameters, you must list the types of those parameters.
For example, to create a command that makes the main camera look at an object, create a new C# script in Unity with the following code:
Add this script to any game object, and it will register the camera_look
in the Dialogue Runner you attach.
You can then call this method like this:
Coroutines can be commands. If you register a command, either using the YarnCommand
attribute, or the AddCommandHandler
method, and the method you're using it with is a coroutine (that is, it returns IEnumerator
, and yields
objects like WaitForSeconds
), Yarn Spinner will pause execution of your dialogue when the command is called.
For example, here's how you'd write your own custom implementation of <<wait>>
. (You don't have to do this in your own games, because <<wait>>
is already added for you, but this example shows you how you'd do it yourself.)
This new method, once registered with a Dialogue Runner, can be called like this:
Functions are units of code that Yarn scripts can call to receive a value.
In additon to the built-in functions that come with Yarn Spinner, you can create your own.
To create a function, you use the YarnFunction
attribute, or the AddFunction
method on a Dialogue Runner. These work very similarly to commands, but with two important distinctions:
Functions must return a value.
Functions are required to be static
.
For example, here's a custom function that adds two numbers together:
When this code has been added to your project, you can use it like this:
Yarn functions can return the following types of values:
string
int
float
bool
Yarn Spinner searches your code for methods that have the YarnCommand
and YarnFunction
attributes when your game first starts up, as well as when a Dialogue Runner is told to run a Yarn Project.
If the Yarn Project's "Search All Assemblies" option is turned on, every assembly definition is searched; if it's turned off, only the assembly definitions specified in the "Assemblies To Search" option is searched. Code that is not in an assembly definition is always included.
By default, Yarn Spinner searches every assembly definition. If you have a large codebase, putting all of the code that contains commands and functions in an assembly definition can reduce the amount of time Yarn Spinner needs to take to find all of the commands and functions.
If "Search All Assemblies" is turned off on your Yarn Projects, and you're seeing errors that mention that a command hasn't been registered, try turning "Search All Assemblies" on. If the error goes away, it means the code for those commands is in an assembly definition that the Yarn Project wasn't using.
This example project demonstrates making a simple dialogue-based game when beginning with only an empty Unity scene.
Display Yarn dialogue in a Unity scene
Allow a player to select between options to respond
Add some static visuals
Yarn Spinner installed in Unity:
Yarn Spinner set up in a text editor:
Open a new Unity 3D project. Ensure Yarn Spinner has been added to the project in the Package Manager as per the .
If the sample empty scene is not visible, you'll need to open it. In the Project Window where project files are displayed, navigate to Assets > Scenes and select SampleScene.unity.
Yarn Spinner for Unity comes with a pre-made UI layer and accompanying utility scripts to handle displaying lines and presenting options from Yarn files. In the Project Window again, navigate to Packages > Yarn Spinner > Prefabs and drag Dialogue System.prefab into the scene.
When the Dialogue System in the scene is selected, the Inspector will display the Yarn Project it is expecting line from. Here, a Yarn Project is a kind of linking file that groups Yarn script files together. To make one, navigate to a sensible place for the file to live (such as a new folder Assets > Dialogue) and right-click the Project Window pane to select Create > Yarn Spinner > Yarn Project.
The existence of Yarn Projects allows larger games with multiple dialogue systems (e.g. main story dialogue, barks, storylets) to separate into multiple projects that pass lines to different UI or systems. This allows an extra level of organisation above separate Yarn files which are typically used to separate story scenes or parts.
However, most games will need only a single Yarn Project.
Select the scene's Dialogue System again and drag the new Yarn Project into the labelled slot in the Inspector.
Now the Yarn Project needs one or more Yarn Scripts to get dialogue from. Just like with the Yarn Project, navigate to the desired file location and select Create > Yarn Spinner > Yarn Script. Then, with the Yarn Project selected, drag the newly created script into the Inspector slot labelled Source Scripts. Click Apply.
By default, a new Yarn Script begins with a single empty node with the name of the file. Open the file, rename the node to Start and put a single line of test dialogue. You may remove the tags
field.
Returning to Unity, pressing the ▶️ button results in the test line being displayed in front of the empty scene world. Pressing Continue will make the UI disappear, as it has reached the end of the script.
Once you've got a basic story, pop back into Unity and check the basics:
For the shape example, let's add some "characters" to the scene. Use Menu > GameObject > 3D Object to add a Sphere, a Cube and a Plane to the scene. Scale up the Plane by adjusting the vaues in the Inspector to Scale = 10, 10, 10
. To put the Sphere and Cube in front of the camera and make the Plane appear as a floor, they'll need to be moved. The following coordinates are about right, using the default location for the Main Camera:
Looking to the Game view, this should appear as two shapes on a floor with the dialogue UI in front.
All this white makes them difficult to distinguish though, so let's colour each Object. Create basic Materials for each by right-clicking the Project Window in the desired file location and select Create > Material three times. Change the colour of each Material to three distinct colours by modifying the Albedo value in the Inspector.
Add a Material to each Object by selecting the desired object and dragging the Material into the Materials > Element 0 under Mesh Renderer in the Inspector.
A playable branching story game with simple static visuals.
An easy way to spice this up is to just add more dialogue with the same characters. Here is an example script that shows how a simple starter script made for testing can grow to a fuller conversation. And it doesn't stop there! Yarn Spinner is perfect for allowing growing projects to remain functional throughout.
Now, let's move onto an example where Yarn Spinner leverages the power of Unity to change things in the scene as well as running dialogue...
Type | Note |
---|---|
So it's time for the actual writing part. Here, I've opened my new Yarn Script in Visual Studio Code with the Yarn Spinner Extension installed as per the . I've written a simple script about a conversation between a blue sphere 🔵, a red cube 🟥 and the player who plays a shape of their choice. Depending on how the player responds to their greeting, the other shapes will either be pleased to meet them or decide they are rude.
You can find this example script below to copy. Or if you need a refresher on how to represent your own story in Yarn, refer to the .
Once any desired visual assets have been added to the scene and the story has received any necessary fleshing out, the game is complete. If you've used this example to add dialogue to your own scene, you may skip ahead to . Otherwise, let's proceed!
Object | X | Y | Z |
---|
This tutorial isn't here to teach you all of Unity. If you need some guidance about aspects outside of Yarn Spinner, you can or there are lots of helpful guides around the web, on YouTube, or created by Unity themselves!
string
Passed directly to the function.
int
Parsed as an integer using Convert.ChangeType.
float
Parsed as an integer using Convert.ChangeType.
bool
The strings "true" and "false" are converted to their respective boolean values, true
and false
. Additionally, the name of the parameter is interpreted as true
.
GameObject
Yarn Spinner will search all active scenes for a game object with the given name. If one is found, that game object will be passed as the parameter; otherwise, null
will be passed.
Component
(or its subclasses)
Yarn Spinner will search all active scenes for a game object with the given name, and then attempt to find a component of the parameter's type on that game object or its children. If one is found, that component will be passed as the parameter; otherwise, null
will be passed.
Main Camera | 0 | 1 | -10 |
Sphere | -1 | 1 | -7.5 |
Cube | 1 | 1 | -7 |
Plane | 0 | 0.5 | 0 |
The Yarn Spinner project was started by Jon Manning, co-founder of Secret Lab.
Yarn Spinner is now maintained by Jon, together with freelance game developer Tim Nugent, Secret Lab colleague Paris Buttfield-Addison, and researcher and freelancer Mars Buttfield-Addison, together with a huge community of open source contributors. ❤️
You can support Yarn Spinner on Patreon.
v0.9 was the first public release on 9 October 2015
v1.0 was released on 8 January 2020
v2.0 was released on 20 December 2021
Secret Lab is an independent games and creative technology studio located in Hobart, Australia.
We’ve been enthusiastically building video games, apps, and technology to showcase culture, history, arts, and narrative experiences since 2008.
We’re the proud creators of Yarn Spinner, and are currently working on the BAFTA- and IGF-winning Night in the Woods.
You can hire us to build your video games, interactive experiences, fancy apps, or to add features to, or support your integration of Yarn Spinner.
Localization is the process of translating and adapting content to a specific language, region or culture.
Yarn scripts are written in human-readable language. This is generally a single language, and (most of the time) will be written in the language that your development team primarily speaks. The language that a Yarn project is written in is called the base language.
However, if you want your dialogue to be understood by people who don't speak this language, you will need to translate it. Yarn Spinner is designed to make it easy to extract the user-facing text of your dialogue into a strings file, which can then be translated into a different language, and then loaded at run-time. You can translate your project into as many languages as you'd like, and Yarn Spinner will handle it for you automatically.
Yarn Spinner is also designed around the idea that a line of dialogue may have assets associated with it. Most commonly, this means an audio file that contains an actor performing the line, so that it can be used in your game as a voice-over. These assets are also localisable.
I just want to add voiceover in a single language. Why do I need to localise, too?
The philosophy of Yarn Spinner's approach to localisation is: if you want your dialogue to be text-only, and in a single language, you don't need to do anything at all. If you want to do anything else, you will need to set up a localisation and manage it using Yarn Spinner's processes.
We've found that most users who want to start using Yarn Spinner want to quickly get dialogue on the screen, and don't want to do lots of work to get the basics going. That's why we make the simple use-case (text only, a single language) as easy to use as we can.
However, if you're building a game that's voice acted, it makes your life significantly easier if you build your systems with localisation in mind from the start. Additionally, if you have the resources to add voice-over to your project, you should also have the resources to translate your game to other languages (even if you only have voice-overs in a single language.)
To that end, we designed it so that voiceover is intimately tied to localisation, so that you have to at least start thinking about localisation at the start of the process.
Localisation: A set of information that describes where to find text and assets for a given language.
Base language: The language that your Yarn script files are written in.
Strings file: A text document that contains translated versions of Yarn lines.
Line ID: A unique code that identifies a line of dialogue or an option in the original source text.
Localised line: The text of a line of dialogue, in a particular locale.
Localised line asset: An asset (for example, an audio clip) that's associated for a particular line, in a particular locale. For example, an audio clip containing the voiceover for the line "Hello there", in German.
Line provider: A component that receives line IDs from the Dialogue Runner, and fetches the localised line and localised line assets (if present) for the player's preferred locale.
In Yarn Spinner, the localisation workflow works like this:
Write your Yarn scripts. This original content is your 'base' localisation.
Add a line ID to each line of dialogue in your script.
Set up localisations in the Yarn Project for each of the languages you wish to support. (This includes your base language.)
For each localisation besides your base language:
Export a strings file.
Translate its contents into another language.
Associate the strings file with the localisation.
If you have assets you want to use with your dialogue, associate the folder that contains those assets with the localisation they belong to, and set up a Line Provider that's able to use those assets (such as an Audio Line Provider.)
During gameplay, set your Line Provider's language to the player's preferred language, and it will fetch the appropriate content for the player to see.
In the following sections, we'll go through each of these steps.
Every Yarn script is associated with a base language. By default, Yarn Spinner sets the base language to that of your current locale. For example, if your computer is set to use Australian English, then Yarn Spinner will use that as the base language.
The base language of a Yarn Script is controlled by the Yarn Project that it's a part of. You can change the language of your base localisation by changing the 'Base Language' setting on a Yarn Project.
In order to match different versions of a line, you need to add a line id to each line of dialogue. A line ID is a tag that appears at the end of a line that uniquely identifies a line of dialogue in your game.
Here's an example of a line of dialogue with a line tag:
In this example, the line of dialogue has a line ID of 1a64a5
.
Yarn Spinner can add line IDs to your dialogue for you. To do this, select your Yarn Project, and click 'Add Line Tags to Scripts'. Yarn Spinner will re-write all of the script files, adding a line ID to any line that doesn't already have one.
You can't generate a strings file unless all of the lines in all of the scripts in the Yarn Project have a line ID.
When you want to prepare a Yarn Project for an additional language, you add a new Localisation in the Yarn Project.
Localisations are how you tell Yarn Spinner where to find the localised lines, and the localised line assets, for a given language.
To create a new Localisation, open the Localisations list in the Yarn Project's Inspector, and click the + button.
Localisations have the following properties:
You can create a localisation for the base language. When you do this, you can provide localised assets for that language.
After you've set up a localisation, you can translate your dialogue into that localisation's language. To do this, you generate a strings file.
A strings file is a text-based spreadsheet, in comma-separated value form, that contains a translated version of your dialogue. Yarn Spinner can generate a strings file for you, based on the line IDs in the dialogue.
You don't need to create a strings file for your base localisation, because Yarn Spinner can generate that for you from your source Yarn scripts. Any localisation whose language ID is the same as your base language will be marked as 'Automatically included'.
To create a strings file, select a Yarn Project, and click the Export Strings as CSV button. Unity will ask where you want to save the file.
A strings file has the following structure:
Once you've exported a strings file, you can translate it into another language: for each row in the database, change the language
column to the new language you're translating into, and the text
column to the translated text of the line.
Only the language
and text
columns should be modified by the translator. Don't modify the others; in particular, if you modify the value in the id
column, Yarn Spinner won't be able to link the translated line to the original version.
Once you have a strings file that's been translated into your target language, you can add it to your Localisation. To do this, drag and drop the translated strings file into the Strings File property of your localisation, and click Apply.
It's possible to update a strings file after you've made changes to your source scripts. For example, you might have added or removed lines, or made changes to the text.
To update a strings file, click the Update Existing Strings Files button at the bottom of the Inspector.
Yarn Spinner will update every strings file that's been added to the Localisations list: new lines will be added, removed lines will be deleted, and lines whose original text has changed since the last time the file was updated will have the text "NEEDS UPDATE" added to the end. This allows you to more easily find which lines need an updated translation.
Localised line assets are assets that are associated with a particular line, in a particular localisation. The most common example of this is voice-over lines, which are audio assets that are associated with each line.
Line Providers are responsible for fetching the appropriate assets for a given line and language. For example, the Audio Line Provider fetches audio clips, and provides them to voice-over dialogue views.
The specific localised line, and localised line assets, that a line provider fetches depends on which language they have been configured to fetch.
The Text Line Provider has a single language option, which controls which language the line will appear in.
The Audio Line Provider has two language options: the language of the text, and the language of the audio files that are retrieved. This means that you can configure it to provide text in one language, and audio in another.
If a line provider is asked to retrieve content for a language that it doesn't have any assets for, it will retrieve the base language version instead.
When writing Yarn scripts, variables come in handy for storing state and user preferences that can persist and impact story dialogue or choices later on. When using Yarn Spinner for Unity, variables from Yarn scripts can be accessed in C# code by using the provided InMemoryVariableStorage
, which acts as a simple dictionary to store variable names with their current values.
This looks something like this:
This allows Yarn types String
, Number
and Boolean
to be stored in memory, and then accessed by this wrapper class that converts them to the C# equivalents string
, float
and bool
, ready for use in your code.
InMemoryVariableStorage
is flexible and extensible, and has utilities for things such as initialising with default variables declared, or serialising to and from JSON. But what if you want to add very custom behaviour to how variables are stored? To keep values somewhere other than in memory, or add side effects to certain operations in a way that wouldn’t work by just extending this default variable storage? Well, you can define your own.
Like other parts of the Unity API for Yarn Spinner, Variable Storage is made possible with the use of abstract classes. Abstract classes in C# work a little bit like interfaces or protocols in other languages, in that they define a class that cannot be instantiated but can be used to make others. In this way, an abstract class is like a set of constraints for some hypothetical subclass you will define later: it can declare certain methods which your subclass must implement for it to work, and it can contain implementations or values of its own which act as defaults that you may or may not choose to override.
In Yarn Spinner for Unity, VariableStorageBehaviour
is an abstract class that can be inherited from. It specifies the methods which Yarn Spinner may call at runtime, which are expected to be dealt with in your implementation:
Now, Yarn Spinner does not care how your custom VariableStorageBehaviour
works beyond that. It simply assumes that you are doing something sensible, and that your subclass will provide the functionality it expects. Some of those expectations cannot be constrained in code, like the required method declarations can, so there is a level of trust here that you (as the implementer of this black box subclass which Yarn Spinner has never seen) will:
Actually store values somewhere. Your code will still compile if your SetValue()
methods are empty or otherwise throw away the values they are given, but this will mean your TryGetValue()
methods will never be able to work.
Actually get the right value for the given key. Your code will still compile if your TryGetValue()
methods return random values from the aether, but this will make your use of these variables in your Yarn script effectively nonsensical. Likewise if you allow setting of multiple values with the same key.
Actually get rid of values when asked to. Your code will still compile if your Clear()
method does nothing, but this means that Yarn script progress or state may never be reset correctly.
Actually check if a key already exists. Your code will still compile if your Contains()
method always returns false, but this will lead to overwriting existing values the next time someone tries to SetValue()
a seemingly unused key that already had a value.
So let’s assume you are not some chaos demon and you actually want to make a Variable Storage that works the way the Yarn Spinner runtime expects, so that you get variables that actually work. You need:
A way to store values of the given types, each associated with a unique key.
A way to get those values back, as the expected type.
A way to get rid of all the previously stored values.
If you were some sort of psycho you could write a class whose SetValue()
method printed out the given key and value on a piece of paper, Contains()
and TryGetValue()
methods that took a snapshot with a camera placed above the printer and read the values back, and a Clear()
method that pushed the paper from the printer tray into a shredder. Yarn Spinner would not care, because it would still do those three things (though probably unreliably, and with some storage limitations).
Some more typical examples of things that gamemakers have wanted their variable storage to do are:
Instead of storing variables in memory in a dictionary, store them on disk or in a database.
Instead of just setting values in the Variable Storage when asked, also update some corresponding variables on the C# side or call a UnityEvent to notify other components that a value has changed.
Instead of simply getting and setting values, run them via some sanitation or transformation, or even interface with an external API.
So let’s break down how you would go about implementing one of those more sensible ideas...
In this example, let’s replace the default Variable Storage implementation with one that stores values in a SQL database. The example code shown makes use of the sqlite-net library—an open source .Net API for SQL—for the creation of a database and tables, but uses vanilla SQL query strings in place of the convenience bindings which are specific to that library.
SQL is a domain-specific language and set of related frameworks that allow the creation and manipulation of relational databases. This will not be a guide to SQL, as there are many good ones already out there, but the TL;DR of SQL is: data is stored in tables, each column has a name and a type, each row is an entry, and some entries may reference entries in other tables that hold related information. SQL queries can be used to connect information from across tables, to get the fields of information you want.
To begin, we need to make a custom class for our new Variable Storage, which should inherit from the VariableStorageBehavour
abstract class.
If you are following along, your IDE will probably throw a hissy fit at this point, because this empty class does not fulfil the requirements defined by the abstract superclass. To conform, we need at least the six methods listed earlier.
So let’s have a think about how each of these would need to work, given a backing of SQL. We need to be able to insert values into tables, check if a value exists in tables with the given key, return the corresponding value for a given key, and remove all entries from tables.
But first, before any values can be set, the database needs to already exist. Set up like this conventionally occurs in the Start()
method:
Next, to create the tables we need to store values in, we need to declare a class that represents a single entry. Its class name will becomes the table name by default, and its field names and types will become the column names and types. Because each column can only hold one type, we’ll need one table for each type.
These classes would look something like this:
The column that will be used to reference or fetch values—and is thus required to be unique within that table—is specified by the [PrimaryKey]
decorator.
Then, to create an empty table in the database, we can call the database connector’s CreateTable()
method with the class we want to represent.
Those familiar with SQL may notice that these tables do not reference each other and thus this is not an ideal use case for SQL. But this is a minimal example for a method that would be more effectively used in larger games with more complex schemas for their data storage or persistence.
Now we can begin filling out our empty method declarations. Beginning with the easiest, Clear()
is just a matter of telling each table in the database to remove all its entries. The query for this is DELETE * FROM TableName
, where the *
means all entries. Executing a query on the database is as simple as calling Execute()
on the database connector with a string parameter of the desired query.
Now to the fiddliest method, TryGetValue()
is the method that needs to figure out whether a value exists for the given key and, if so, return it as the correct type. This requires a little bit of C# generics.
First we need to do some switching of which table we need to look for the value in:
Then, within each, we should look for that key within the corresponding table. To return only the value from any row that matches our variable name we specify Select ColumnName FROM TableName WHERE (conditions to match)
.
To make sure the compiler knows what T
is at compile time, results must be cast to object
and then back to T
(thanks, C#!).
Next, before we can begin inserting values into tables, we first want to make sure a value doesn’t already exist for that key in another table. We can do this by creating a utility method that uses a lookup query to check if a value exists with that key in a specific table. This can take advantage of our TryGetValue()
implementation:
...which can then also be used as the basis for our Contains()
method, by checking them all:
This utility method then also comes in handy when defining the SetValue()
methods, which would each look something like this:
In production, you should always validate and sanitise input before inserting it into SQL, in case our string value itself contains invalid syntax or partial SQL commands. Otherwise, you may leave yourself open to SQL injection attacks.
And lo! We should now have a fully functioning SQL-backed custom Variable Storage for Yarn Spinner. Simply replace the Variable Storage component on the DialogueRunner
game object in your scene to put your custom implementation to work.
As far as Yarn Spinner is concerned, this should behave exactly as the provided InMemoryVariableStorage
does at runtime, even though the entire storage model and behaviour has changed.
Using this simple method of overriding methods in the inbuilt VariableStorageBehaviour
abstract class, you can make a custom Variable Storage backed by virtually anything to suit your needs!
Check out the documentation on Variable Storage or ask the community in the Yarn Spinner Discord Server!
This example project demonstrates making a simple non-linear dialogue-based game when beginning with some pre-existing assets.
Display Yarn dialogue in a Unity scene
Allow a player to select between options to respond
Allow a player to select among available characters to speak to
Use Yarn Spinner to trigger a command that changes the interactability of characters
Yarn Spinner installed in Unity
Yarn Spinner set up in a text editor
Starter Asset Package downloaded and unzipped
Open a new Unity 3D project. Ensure Yarn Spinner has been added to the project in the Package Manager as per the Installation Instructions.
Drag the provided Asset Package into the Project Window where project files are displayed in Unity to import them into the project.
This package includes the following assets and functionality:
A simple, static environment called Graveyard which also contains four character models.
A C# script that provides simple functions for the character objects.
A Timeline that stores the hovering animation for the Ghost character.
Some Lights that turn on and off to indicate when a Grave character is speaking.
The next step is to import the Dialogue System and hook up a Yarn Project and Yarn Script. If you have completed Example Project 1 or Example Project 2 before, you may skip ahead to Filling Out Your Script. Otherwise, let's proceed!
Yarn Spinner for Unity comes with a pre-made UI layer and accompanying utility scripts to handle displaying lines and presenting options from Yarn files. In the Project Window again, navigate to Packages > Yarn Spinner > Prefabs and drag Dialogue System.prefab into the scene.
When the Dialogue System in the scene is selected, the Inspector will display the Yarn Project it is expecting line from. Here, a Yarn Project is a kind of linking file that groups Yarn script files together. To make one, navigate to a sensible place for the file to live (such as Assets > Dialogue) and right-click the Project Window pane to select Create > Yarn Spinner > Yarn Project.
The existence of Yarn Projects allows larger games with multiple dialogue systems (e.g. main story dialogue, barks, storylets) to separate into multiple projects that pass lines to different UI or systems. This allows an extra level of organisation above separate Yarn files which are typically used to separate story scenes or parts.
However, most games will need only a single Yarn Project.
Select the scene's Dialogue System again and drag the new Yarn Project into the labelled slot in the Inspector.
Now the Yarn Project needs one or more Yarn Scripts to get dialogue from. Just like with the Yarn Project, navigate to the desired file location and select Create > Yarn Spinner > Yarn Script. Then, with the Yarn Project selected, drag the newly created script into the Inspector slot labelled Source Scripts. Click Apply.
By default, a new Yarn Script begins with a single empty node with the name of the file. Open the file, rename the node to Start and put a single line of test dialogue. You may remove the tags
field.
Returning to Unity, pressing the ▶️ button results in the test line being displayed in front of the graveyard scene. Pressing Continue will make the UI disappear, as it has reached the end of the script.
It's time to plan a story. In the scene there are four characters—Ghost, LeftGrave (Louise), CenterGrave (Carol), and RightGrave (Ruby)—and the intent of this game is for the player to be able to interact with them in virtually any order to complete the objectives of the game. This game format typically accompanies stories where the player must piece together information from smaller tidbits given to them when they speak to different characters.
For example: neither Witness A nor B knew who stole the cookie from the kitchen, however:
Witness A knew the cookie was taken in the morning.
Witness B knew that Suspects A and B entered the kitchen in the morning and afternoon, respectively.
Together, their clues show that Suspect A must have eaten the cookie.
So, when the game begins, Ghost will present some mystery. Once a brief context-establishing conversation ends, the player will be free to select which character to speak to next. Speaking to each of the Grave characters will present a clue, provided the required prerequisite clues are known. At any time, the player can present their collated clues to Ghost. If their clues are complete, Ghost will tell them they solved the mystery and the game will end.
This short story provides a looping circuit through four paths, and results in the player reaching the ending after an undetermined number of conversations (though there is a hypothetical minimum, there is no maximum). A railroad diagram representation of the story would look as follows:
So it's time for the actual writing part. Here, I've opened my new Yarn Script in Visual Studio Code with the Yarn Spinner Extension installed as per the Installation Instructions. I've written a minimal script that follows the planned story, as a skeleton that can be expanded on later.
In this script, selecting the correct conversation option when speaking to each character will yield a new clue. However, the correct option is only available if the player has the required prerequisite clues. So no matter the order the player speaks to the graves, they must acquire clues in the order A then B then C.
The most notable part about this script is that there are no jump statements in the file at all; each node is completely disconnected from the rest. Instead, we will be requesting and jumping to specific nodes manually from within Unity.
You can find this example script below to copy. Or if you want to make you own version and need a refresher on how to represent it in Yarn, refer to the Syntax and File Structure guide.
Once you've got a basic story, pop back into Unity and check the basics:
Note that at this point, there is no way to progress beyond the intro conversation with Ghost. All other nodes cannot be reached with the code we have written so far.
In this game, the player should be able to select an NPC in the scene and have it trigger their repsective conversation. This requires a few things:
Code to begin dialogue from a specific node when a character object is interacted with.
Code to disable scene interaction when any character is already speaking.
Code to disable character interaction when a specific character should not be interactable.
In Assets > Scripts there is a C# script that has code to do these things (see headers below), so we just need to connect it to the appropriate places. But first, let's step through what it does.
Add the YarnInteractable script to each character in the game: Ghost, LeftGrave, CenterGrave, and RightGrave. Make sure to set their respective conversationStartNode
values in the Inspector to match what they are called in the Yarn script.
First up is the code for beginning a conversation. This requires running dialogue from a specific node when a character is interacted with. Running dialogue is a simple matter of telling the DialogueRunner to begin dialogue and passing the name of the node to begin from as a string.
To run this when a character is interacted with, simple override the OnMouseDown()
function that exists for every GameObject (which this class inherits from). Checking the IsDialogueRunning
property of the DialogueRunner is a simple way to ignore interaction whenever starting dialogue would interrupt an existing conversation.
This handles beginning a conversation, but what if other changes are needed while a character is speaking? Well, having a function that is triggered when a conversation ends would allow properties to be set in StartConversation
that can then be reversed once dialogue has ended.
In a typical game, several changes would be triggered when beginning or ending dialogue, such as changing UI mode and starting and stopping a speaking animation on the relevant character or similar. So it's sensible to have bookend functions that hold all this code, even if we won't be doing anything useful with EndConversation()
until later.
To trigger a function when a conversation ends, a listener can be added to the DialogueRunner that will fire a specified function when a certain event occurs. The onDialogueComplete
event happens whenever the runner reaches the end of its current conversation path.
Next, let's define the function it will call. A key consideration here is that every object using this YarnInteractable script will be notified of dialogue completion every time it happens. Each one is registering a listener, and each will have its own EndConversation()
function be called.
So to save some work, we can check whether this is the instance that should care about the event. This can be done just by setting a boolean when the conversation begins, that says this is the character that is currently speaking.
Returning to Unity, press the ▶️ button and see that this now allows a new conversation to be triggered by interacting with any character after another has finished speaking.
At this point, this may seem done, but there is a critical issue here. Looking back at the earlier goals:
Why that third thing? Well, because the current state of the game allows the player to:
Speak to the Ghost to begin the story.
Ask the Graves about the mystery.
Speak to the Ghost once they have collected the necessary clues.
Have Ghost tell them they ✨ solved the mystery ✨ and say goodbye.
Go back and still ask the Graves about the mystery that is already solved(?!)
So there needs to be a way to tell a specific character "no, you are done, don't speak to the player any more". This can be done with a simple Yarn Command.
In YarnInteractable.cs there is a simple function that sets a flag that the OnMouseDown()
function checks when deciding whether to start a conversation. Turning this into a command simple requires adding the Yarn Command decorator above the function, with the string that will become the command keyword in any yarn scripts.
Back in the Yarn script, call disable
once for each character when the story ends, to save the player from going back and having a confusion conversation about an already-solved mystery.
And that's it for the dialogue behaviours! Back in Unity, characters should speak when interacted with—but not when it would interrupt another, or when the story has ended.
Now that all the behaviours are working and the skeleton story plays through correctly, it's time to replace the skeleton placeholder script with the full story and add some polish. In Assets > Dialogue find the file GhostyLads_FinalVersion.yarn. In the Yarn Project created earlier, replace the script you placed in Source Scripts earlier with this script instead.
Next, let's add an indicator so the player more easily knows which character is currently speaking.
Because I am not an animator, I have used only static objects as characters in this demo game. To indicate who is speaking, I will be using a simple spotlight that turns on and off above the speaker. I will not be taking questions at this time.—Mars, 2022.
In the scene, each grave object also contains a green spotlight which is currently assigned to a variable called lightIndicatorObject
in YarnInteractable.cs, so a snippet of code in each of theStartConversation()
and EndConversation()
functions can quickly turn it on and off for the relevant character.
Now, a light should turn on above any grave who is currently speaking.
A playable whodunnit-like game with multiple characters that can be spoken to in any order to solve a mystery from partial clues available.
An easy way to spice this up is to just try replacing provided assets with ones of your own choosing. There are plenty of publically available asset packs with permissive licenses to play with, and re-theming a starter game and building from there can be easier than starting from scratch.
You could add more characters, or even design a more complex conversation structure that must be navigated to solve the mystery! Yarn Spinner is great at telling complex non-linear stories where player choices matter.
Learn about Yarn Spinner's amazing community projects, by the community, because they're community projects.
Community projects are written by our wonderful community. These are not supported or maintained by the Yarn Spinner team, but you might find them useful.
If you've written a high-quality project that works with Yarn Spinner, please get in touch via or ! We'd love to show it off. ❤️
, by : An implementation of a Language Server for the Yarn Spinner compiler, designed for use with Visual Studio and Visual Studio Code.
, by : A visual editor for writing Yarn script.
, by : An implementation of the Yarn Spinner compiler in GDScript.
, by : An implementation of Yarn Spinner for the game engine, based on GDYarn.
, by : A Visual Studio Code extension that embeds the Yarn Classic editor.
There are several official Yarn Spinner GitHub repositories:
Yarn Spinner Core —
This is the core of Yarn Spinner, and all other elements depend on this in some way.
Yarn Spinner Unity —
This is the components of Yarn Spinner that relate to the Unity integration
Yarn Spinner Console (ysc
) —
The Yarn Spinner command-line tool, for working with .yarn
files on the command-line.
Visual Studio Code Extension —
This is the VS Code extension for Yarn Spinner.
We also host several other public GitHub repositories related to Yarn Spinner:
Experimental Editor -
This is an experimental editor created by a student team. It may, or may not, be maintainted in the future. It targets Yarn Spinner 2.0.
Classic Yarn Editor -
This is the Classic Yarn Editor, and is not supported by Yarn Spinner.
Property | Description |
---|---|
Column | Description |
---|---|
Name | Description |
---|
Name | Description |
---|
Name | Description |
---|
Language ID
The language for this localisation.
Strings File
A Text Asset containing the translated lines for this Yarn Project's scripts. See Creating a Translation for information on how to create these assets.
Assets Folder
A folder containing the localised assets for this localisation.
language
The language code for this line.
When you export a strings file, this will be the Yarn project's base language.
id
The line ID for this line.
text
The text of the line, in the language indicated by the language
column.
file
The file that the line was originally found in.
node
The node that the line was originally found in.
lineNumber
The line number of the file that the line was originally found in.
lock
A unique value that Yarn Spinner uses to detect if the line has been modified since the strings file was generated. Don't modify or delete this value.
comment
A note indicating the intent and tone of the line. This can be useful for translators who may not have the same background or context for how the line should be delivered.
TryGetValue(string variableName, out T result)
Look to see if variableName
exists and can be cast to the given type and, if so, return its value.
SetValue(string variableName, string stringValue)
Store the value stringValue
and somehow attribute it with the key variableName
.
SetValue(string variableName, float floatValue)
Store the value floatValue
and somehow attribute it with the key variableName
.
SetValue(string variableName, bool boolValue)
Store the value boolValue
and somehow attribute it with the key variableName
.
Clear()
Remove, release or otherwise un-attribute all previously set variable names, such that calling TryGetValue()
without first calling SetValue()
with the same key would now fail.
Contains(string variableName)
Return whether a particular variableName
exists as a key in the storage at this moment.
Property in BuiltinTypes
Gets a dictionary that maps CLR types to their corresponding Yarn types.
Contains the built-in types available in the Yarn language. |
Co-ordinates the execution of Yarn programs. |
A type that represents functions. |
A collection of functions that can be called from Yarn programs. |
A compiled Yarn program. |
Represents the method that is called when the dialogue has reached its end, and no more code remains to be run. |
Represents the method that is called when the Dialogue reaches the end of a node. |
Represents the method that is called when the Dialogue begins executing a node. |
Represents the method that is called when the dialogue anticipates that it will deliver lines. |
Defines properties that describe a type in the Yarn language. |
Provides a mechanism for storing and retrieving instances of the |
Contains classes for compiling Yarn code. |
Contains classes for working with markup in Yarn lines. |
Contains classes for working with Yarn Spinner in the Unity game engine. |
Gets the type representing any value. |
Gets the type representing boolean values. |
Gets the type representing numbers. |
Gets the type representing strings. |
Gets a dictionary that maps CLR types to their corresponding Yarn types. |
This example project demonstrates making a simple dialogue-based game when beginning with some pre-existing assets.
Display Yarn dialogue in a Unity scene
Allow a player to select between options to respond
Use Yarn Spinner to trigger commands that change the scene, camera and characters
Yarn Spinner installed in Unity
Yarn Spinner set up in a text editor
Starter Asset Package downloaded and unzipped
Open a new Unity 3D project. Ensure Yarn Spinner has been added to the project in the Package Manager as per the Installation Instructions.
Drag the provided Asset Package into the Project Window where project files are displayed in Unity to import them into the project.
To see the Scene containing the imported assets, you'll need to open it. In the Project Window, navigate to Assets > Scenes and select SpaceJourney.unity.
This package includes with the following assets and functionality:
A simple, static environment called Spaceship.
Three Character models that each come with 6 available poses and 5 facial expressions.
UI Layers that appear in front of the camera to present a black screen or title screen.
Location Markers which are named but invisible objects in the scene that can act as anchors to move other objects to predefined positions.
Four C# scripts that are attached to some of the above objects to provide simple functions.
So the Scene looks somewhat like this, except that Locations and the markers within them are invisible. Here, orange diamond 🔶 icons are markers intended for the camera to move to and blue circle 🔵 icons are intended for characters.
You can see these markers yourself in Unity by selecting each marker in Location Markers and allocating them an Icon using the dropdown at the top of the Inspector. The markers named Camera
are the camera markers and the ones named like Left
or Right
are character markers.
The next step is to import the Dialogue System and hook up a Yarn Project and Yarn Script. If you have completed Example Project 1 before, you may skip ahead to Filling Out Your Script. Otherwise, let's proceed!
Yarn Spinner for Unity comes with a pre-made UI layer and accompanying utility scripts to handle displaying lines and presenting options from Yarn files. In the Project Window again, navigate to Packages > Yarn Spinner > Prefabs and drag Dialogue System.prefab into the scene.
When the Dialogue System in the scene is selected, the Inspector will display the Yarn Project it is expecting line from. Here, a Yarn Project is a kind of linking file that groups Yarn script files together. To make one, navigate to a sensible place for the file to live (such as Assets > Dialogue) and right-click the Project Window pane to select Create > Yarn Spinner > Yarn Project.
The existence of Yarn Projects allows larger games with multiple dialogue systems (e.g. main story dialogue, barks, storylets) to separate into multiple projects that pass lines to different UI or systems. This allows an extra level of organisation above separate Yarn files which are typically used to separate story scenes or parts.
However, most games will need only a single Yarn Project.
Select the scene's Dialogue System again and drag the new Yarn Project into the labelled slot in the Inspector.
Now the Yarn Project needs one or more Yarn Scripts to get dialogue from. Just like with the Yarn Project, navigate to the desired file location and select Create > Yarn Spinner > Yarn Script. Then, with the Yarn Project selected, drag the newly created script into the Inspector slot labelled Source Scripts. Click Apply.
By default, a new Yarn Script begins with a single empty node with the name of the file. Open the file, rename the node to Start and put a single line of test dialogue. You may remove the tags
field.
Returning to Unity, pressing the ▶️ button results in the test line being displayed in front of the empty scene world. Pressing Continue will make the UI disappear, as it has reached the end of the script. If you do not see this, read onward for a common fix.
If you only see a black screen, the included fade-to-black layer is turned on and blocking the camera from seeing the scene. Hide this by selecting UI Layers from the Scene Hierarchy and unchecking the box at the top of the Inspector.
It's time to plan a story. In this Asset Package there are three character models called Engineer, Crewmate and Captain.
These low-poly spacefarers live and work on a spaceship with the player. It's a new day on the job in Space Fleet, the player is in the corridor and they must decide which of their three shipmates they're going to speak to. The choices presented are:
The Engineer, who will complain to the player about his job.
The Crewmate, who the player will attempt to convince should give them extra rations.
The Captain, who will try to judge whether the player is ready for action.
After a short conversation with the chosen character, a shipwide alert requests all hands report to the bridge. When the player arrives, the Captain reveals that space pirates are attacking. Then one of two things happens:
If the player chose to speak to the Captain earlier, and succeeded in convincing her that they were ready for action, the player is sent to fight off the pirates and save the day.
If the player either didn't speak to the Captain, or failed to convince her that they were ready for action, the Crewmate is sent instead.
This short story provides an initial choice between three paths, and results in the player achieving one of two endings. A tree representation of the story would look as follows:
So it's time for the actual writing part. Here, I've opened my new Yarn Script in Visual Studio Code with the Yarn Spinner Extension installed as per the Installation Instructions. I've written a minimal script that follows the planned story, as a skeleton that can be expanded on later.
You can find this example script below to copy. Or if you want to make you own version and need a refresher on how to represent it in Yarn, refer to the Syntax and File Structure guide.
Once you've got a basic story, pop back into Unity and check the basics:
Speaking to an empty void is all well and good, but this particular game is going to be more compelling if it makes use of the provided assets to make dynamic visuals. So to empower our Yarn script to invoke changes in Unity, we'll make some Commands. For this project, we'll make commands to:
Move the Camera to preset locations, as if the player is moving.
Turn on and off UI elements, to create nice transitions during Scene changes.
Move Character models to preset locations, as if they are entering and exiting the Scene.
Change Character model animations and textures, as if they are showing different emotions.
The first two will need to exist throughout the Scene, while the next two should attach to specific Character objects so each can be controlled independently. In Assets > Scripts there are four C# scripts that have code to do each of these things (see headers below), so we just need to create commands that make the functionality available to Yarn scripts in the project.
Code for the scene-wide commands are included in Assets > Scripts > SceneDirector.cs. To make functions from the script available throughout the project, it is attached to an otherwise empty GameObject in the Scene called Scene Director.
With our first command we want to be able to be able to move the Scene's Main Camera to an invisible marker in the Scene with the given name. The function from SceneDirector.cs that we want to be able to invoke from Yarn is called MoveCamera()
and it looks like this:
It takes a Location in the Scene, from the eligible options Title, Corridor and Bridge. **It then finds the location and facing of the marker named Camera in that Location** and sets the camera location and facing to that of the marker.
If the camera moves to the Title location, the Title Layer element will fill the screen and appear as if a splash screen was being shown. If moved to the Corridor or Bridge locations, it acts as the point of view of the player who is then seen to be currently in that location. The default camera location is Title.
Here, we want to make a Yarn command called camera
that takes a location name and knows to pass it off to the MoveCamera()
function in C# to make it happen. This will mean when the player has to move to the bridge, the Yarn script can just say <<camera Bridge>>
.
Making a command that can then be used in Yarn is as simple as registering a Command Handler. A Command Handler tells the Dialogue System that a Yarn command exists with a given name, how many additional pieces of information it needs, and which C# function to pass this information to when it's called. Then, when the game runs, the Dialogue System will handle talking to C# for you.
Command Handlers have two important requirements:
They must be created before the command can ever be called. Usually, this means you want to make it as part of the initial creation of the scene or the object it's attached to.
They must be attached to the Dialogue System's Dialogue Runner object. It's the thing passing lines of dialogue to the scene that has to know to change behaviour if the next line it receives is a command instead of dialogue.
To satisfy the first point, we can register any Command Handlers in a function called Awake()
that every Unity object has by default. This function is called when the object is created, and because our empty Scene Director object is always in the Scene this means it gets created as soon as the Scene does. Registering Command Handlers in the Awake()
function of this object therefore means they will be registered before anything else happens when the game is run.
To satisfy the second, we need to find the Dialogue Runner in the scene and assign it to a variable in C# that we can then attach Command Handlers to. Because there is only one Dialogue Runner in the Scene, we can find it by asking Unity to give us all the objects in can find in the Scene of type DialogueRunner.
Altogether, this means two simple lines in the Awake()
function of SceneDirector.cs:
The Dialogue Runner now supports a command called camera
that has a parameter of type Location
and will defer to the function MoveCamera()
to make it happen.
Return to the Yarn script and add commands of syntax <<camera (location name)>>
to the appropriate places:
Add <<camera Corridor>>
to the top of the Start node.
Add <<camera Bridge>>
to the top of the node where characters should move to the bridge.
To show the title before the game begins, add <<camera Title>>
at the top of Start and then a call to the inbuilt <<wait (number of seconds)>>
command to hold for a second or two before moving to the Corridor.
If you hid the Title Layer object earlier, be sure to unhide it now by selecting it and re-ticking the box at the top of the Inspector. If necessary, unhide UI Layers and re-hide just the Fade Layer.
These minimal changes to the Yarn script...
...should now result in the camera moving around the empty environment in the appropriate points in the script. Returning to Unity, press the ▶️ button and playthrough to check this works correctly.
When Yarn script needs to pass an argument of a project-specific type (like Location is) it simply searches the scene for objects of that type with the given name, so make sure you spell and capitalise Location names exactly as they are in the Scene.
Onto the next command! Smash cuts are fine, but nice transitions are fancier. In the Scene there is a flat black layer called Fade Layer that sits in front of the camera. Changing its opacity can make the camera appear to fade to and from black. Back in SceneDirector.cs there is a line in the Awake()
function that finds the objects of type Fade Layer in the Scene (there is only the one) and keeps it in a variable called fadeLayer
, similar to how the Dialogue Runner was found earlier.
Remember to unhide the Fade Layer if you hid it earlier, otherwise this command won't be able to find it. Re-tick the box at the top of the Inspector.
Then further down the file there are short functions called FadeIn()
and FadeOut()
that do just that, by changing the opacity of this stored layer over the given number of seconds (or defaulting to 1 second if no argument is provided).
These functions are a little different in that instead of returning nothing like the MoveCamera()
function did, these functions return a Coroutine
. This gives Yarn Spinner a handle to the process it triggered so that for operations that take time (like fading in a screen over a second or so) it knows not to trigger the next line of dialogue until that process has completed.
Again, the functionality that performs the actual opacity change is contained in a C# script attached to the relevant GameObject. In this case it is a file called FadeLayer.cs attached to the Fade Layer.
Adding commands for fadeIn
and fadeOut
works just like before. In the Awake()
function of SceneDirector.cs by adding Command Handlers to the previously found Dialogue Runner.
Back in the Yarn script, add a <<fadeOut>>
and <<fadeIn>>
to either side of each camera or node change to make nice fade-to-black transitions between story parts. Because no argument is provided, this will perform a 1 second fade.
Including transitions between conversation nodes even if they occur in the same Corridor location will hide the characters appearing that will be implemented next.
All this took is a few more additions to the Yarn script:
The next command will allow character models to be placed in the Scene whenever they are part of the current conversation. We could write these as before in SceneDirector.cs with a function that takes a Character to change and what to change about them, but instead we're going to try out another type of command.
This time, we're going to add commands to the script that's attached to each Character-typed object in the scene, found at Assets > Scripts > Character.cs. This script has three main functions we want to use: Move()
, SetPose()
and SetExpression()
.
In our example nobody ever leaves a location while the player is still there so there's no need to implement hide/show-like functionality; we can just cycle Characters between predefined Locations in the Scene.
First up in Character.cs, there is a function called Move()
that accepts a Location
object and the name of a marker in that Location. It looks very similar to the MoveCamera()
function used earlier:
Much like before with MoveCamera()
, Yarn Spinner is able to find the Game Object you are trying to command by searching the Scene for one with the right type and name. This is used to find the Location that should be passed as the first function argument, but also to specify the target Character this function should be called on.
So if we want a command like <<place (location) (marker name)>>
we need to add an extra argument in between to specify the target Character object: <<place (character) (loc...>>
.
But this can't be done like before with a Command Handler registered when the object is created. Because Character.cs is attached to every Character object in the Scene, the Awake()
function would be called every time any Character was created. This would result in the Dialogue Runner receiving multiple registrations of command with the same name but that are requested to pass off to different objects. Yarn Spinner won't allow that, so we have to instead annotate the relevant functions using the Yarn Command decorator.
Declaring a Yarn Command is as simple as adding [YarnCommand("command name")]
to the declaration of a function. Add the following decorator to just above the Move()
function:
Now in the Yarn script, just add commands to move the relevant Character to the desired marker in the current Location by adding <<place (character name) (location) (marker name)>>
wherever needed. Placing characters before calling <<fadeIn>>
will ensure they are there before the shot appears, so the Character won't seem to pop into existence a fraction later.
Just a handful of additions to the Yarn script:
And now our Characters appear in the Scene whenever they're part of the current conversation.
Next, we're going to add some pose and facial expression changes to make Characters respond to the changing mood of the story. Primarily because it's a bit weird that everyone looks so cheerful during a crisis...
The SetPose()
function in Character.cs accepts the name of a pose and tells the animator attached to the Character model to move the model to that pose. The available poses for each model are defined by their underlying type seen in Assets > Art > CharacterBaseModels and the Asset Package has come with the following for both male and female models:
neutral
hand-on-hip
arms-out
hand-at-mouth
pointing
hands-on-hips
Mostly these just move their arms into different basic positions. The function looks like this:
As with the place
command, add a decorator to SetPose()
to declare a command called pose
.
Now characters can be moved using <<pose (character) (pose name)>>
wherever called for in the script. In particular, adding appropriately unhappy-looking poses during the Bridge scene will make Characters seem to respond to the story.
Next, do the exact same thing for expressions. The options included for each character in the Asset Package are:
neutral
happy
angry
smirk
surprised
Facial expressions for the included characters are just a texture applied to the model's face, so changing expression just means asking the texture renderer to change face texture.
Decorate with [YarnCommand("expression")]
and, back in the Yarn script, place calls to <<expression (character) (expression name)>>
wherever appropriate.
And that's it for commands! We successfully implemented commads to:
Now that all the commands are hooked up and the skeleton story plays through correctly, it's time to replace the skeleton placeholder script with the full story. In Assets > Dialogue find the file SpaceJourney_FinalVersion.yarn. In the Yarn Project created earlier, replace the script you placed in Source Scripts earlier with this script instead.
A playable visual novel-type game with multiple characters and scenes and sensible transitions between them.
An easy way to spice this up is to just try replacing provided assets with ones of your own choosing. There are plenty of publically available asset packs with permissive licenses to play with, and re-theming a starter game and building from there can be easier than starting from scratch.
Or you could try your hand at C# and create more advanced commands that can be made available to Yarn. Add new Locations, or camera motion. The sky's the limit! Yarn Spinner is perfect for allowing iterative and creative development.
Now, let's move onto an example that uses Yarn Spinner to run different dialogue based on players interacting with different NPCs...
Struct in Yarn
Inherits from System.ValueType
A command, sent from the Dialogue to the game.
You do not create instances of this struct yourself. They are created by the Dialogue during program execution.
Name | Description |
---|---|
Dialogue.CommandHandler: Gets or sets the CommandHandler that is called when a command is to be delivered to the game.
Delegate in
Inherits from System.MulticastDelegate
Represents the method that is called when the Dialogue delivers a .
Name | Description |
---|
: Represents the method that is called when the Dialogue delivers a .
: Represents the method that is called when the Dialogue delivers an .
: Represents the method that is called when the Dialogue begins executing a node.
: Represents the method that is called when the Dialogue reaches the end of a node.
: Represents the method that is called when the dialogue has reached its end, and no more code remains to be run.
Method in
Starts, or continues, execution of the current Program.
This method repeatedly executes instructions until one of the following conditions is encountered:
The or is called. After calling either of these handlers, the Dialogue will wait until is called. Continue may be called from inside the or , or may be called at any future time.
The is called. When this occurs, the Dialogue is waiting for the user to specify which of the options has been selected, and must be called before is called again.)
The Program reaches its end. When this occurs, must be called before is called again.
An error occurs while executing the Program.
This method has no effect if it is called while the is currently in the process of executing instructions.
: Represents the method that is called when the Dialogue delivers a .
: Represents the method that is called when the Dialogue delivers an .
: Represents the method that is called when the Dialogue delivers a .
: Represents the method that is called when the Dialogue reaches the end of a node.
: Represents the method that is called when the dialogue has reached its end, and no more code remains to be run.
An exception that is thrown by when there is an error in executing a .
A simple concrete implementation of that keeps all variables in memory.
A node of Yarn script, contained within a , and containing Yarn.Instruction
s.
Represents the method that is called when the Dialogue delivers a .
Represents the method that is called when the Dialogue delivers a .
Represents a method that receives diagnostic messages and error information from a .
Represents the method that is called when the Dialogue delivers an .
A command, sent from the to the game.
A line of dialogue, sent from the to the game.
A set of s, sent from the to the game.
Name | Description |
---|
Gets the text of the command.
The node that execution will start from. |
Starts, or continues, execution of the current Program. |
Replaces all substitution markers in a text with the given substitution list. |
Returns the string ID that contains the original, uncompiled source text for a node. |
Returns the tags for the node |
Gets a value indicating whether a specified node exists in the Program. |
Unloads all nodes from the Dialogue. |
Gets the name of the node that this Dialogue is currently executing. |
Gets a value indicating whether the Dialogue is currently executing Yarn instructions. |
Invoked when the Dialogue needs to report debugging information. |
Invoked when the Dialogue needs to report an error. |
Gets the names of the nodes in the currently loaded Program. |
Gets or sets the object that provides access to storing and retrieving the values of variables. |
program | The additional program to load. |
command | The that has been delivered. |
variableStorage | The that this Dialogue should use. |
Method in Dialogue
Gets a value indicating whether a specified node exists in the Program.
Name | Description |
---|---|
true
if a node named nodeName
exists in the Program, false
otherwise.
Method in Dialogue
Returns the string ID that contains the original, uncompiled source text for a node.
A node's source text will only be present in the string table if its tags
header contains rawText
.
Because the Dialogue class is designed to be unaware of the contents of the string table, this method does not test to see if the string table contains an entry with the line ID. You will need to test for that yourself.
Name | Description |
---|---|
The string ID.
Method in Dialogue
Parses a line of text, and produces a MarkupParseResult containing the results.
The MarkupParseResult 's Text will have any select
, plural
or ordinal
markers replaced with the appropriate text, following this Dialogue 's LanguageCode .
Name | Description |
---|---|
The results of parsing the markup.
Method in Dialogue
Prepares the Dialogue that the user intends to start running a node.
After this method is called, you call Continue() to start executing it.
If PrepareForLinesHandler has been set, it may be called when this method is invoked, as the Dialogue determines which lines may be delivered during the startNode
node's execution.
Name | Description |
---|---|
Method in Dialogue
Replaces all substitution markers in a text with the given substitution list.
This method replaces substitution markers - for example, {0}
with the corresponding entry in substitutions
. If text
contains a substitution marker whose index is not present in substitutions
, it is ignored.
Name | Description |
---|---|
text
, with the content from substitutions
inserted.
Method in Dialogue
Returns the tags for the node nodeName
.
The tags for a node are defined by setting the tags
header in the node's source code. This header must be a space-separated list.
Name | Description |
---|---|
The node's tags, or null
if the node is not present in the Program.
Initializes a new instance of the class.
Loads the nodes from the specified , and adds them to the nodes already loaded.
Parses a line of text, and produces a containing the results.
Prepares the that the user intends to start running a node.
Loads all nodes from the provided .
Signals to the that the user has selected a specified .
Immediately stops the .
Gets or sets the that is called when a command is to be delivered to the game.
Gets or sets the that is called when the dialogue reaches its end.
Gets or sets the 's locale, as an IETF BCP 47 code.
Gets the that this Dialogue uses to locate functions.
Gets or sets the that is called when a line is ready to be shown to the user.
Gets or sets the that is called when a node is complete.
Gets or sets the that is called when a node is started.
Gets or sets the that is called when a set of options are ready to be shown to the user.
Gets or sets the that is called when the dialogue anticipates delivering some lines.
string
nodeName
The name of the node.
string
nodeName
The name of the node.
string
line
The line of text to parse.
string
startNode
The name of the node that will be run. The node have been loaded by calling SetProgram(Program) or AddProgram(Program) .
string
text
The text containing substitution markers.
System.Collections.Generic.IList<string>
substitutions
The list of substitutions.
string
nodeName
The name of the node.
Property in Dialogue
Gets or sets the CommandHandler that is called when a command is to be delivered to the game.
Method in Dialogue
Loads all nodes from the provided Program .
This method replaces any existing nodes have been loaded. If you want to load nodes from an additional Program, use the AddProgram(Program) method.
Name | Description |
---|---|
Yarn.Program program
The Program to use.
Method in
Signals to the that the user has selected a specified .
After the Dialogue delivers an , this method must be called before is called.
The ID number that should be passed as the parameter to this method should be the field in the that represents the user's selection.
Name | Description |
---|
: Represents the method that is called when the Dialogue delivers an .
: A set of s, sent from the to the game.
: Starts, or continues, execution of the current Program.
| The ID number of the Option that the user selected. |
Property in Dialogue
Gets the name of the node that this Dialogue is currently executing.
If Continue() has never been called, this value will be null
.
Method in Dialogue
Immediately stops the Dialogue .
The DialogueCompleteHandler will not be called if the dialogue is ended by calling Stop() .
Property in Dialogue
Gets or sets the DialogueCompleteHandler that is called when the dialogue reaches its end.
Property in Dialogue
Gets or sets the LineHandler that is called when a line is ready to be shown to the user.
Property in Dialogue
Gets a value indicating whether the Dialogue is currently executing Yarn instructions.
Property in Dialogue
Gets or sets the NodeCompleteHandler that is called when a node is complete.
Property in Dialogue
Gets or sets the OptionsHandler that is called when a set of options are ready to be shown to the user.
The Options Handler delivers an OptionSet to the game. Before Continue() can be called to resume execution, SetSelectedOption(int) must be called to indicate which Option was selected by the user. If SetSelectedOption(int) is not called, an exception is thrown.
Property in Dialogue
Gets or sets the PrepareForLinesHandler that is called when the dialogue anticipates delivering some lines.
Property in Dialogue
Gets or sets the object that provides access to storing and retrieving the values of variables.
Delegate in Yarn
Inherits from System.MulticastDelegate
Represents the method that is called when the dialogue has reached its end, and no more code remains to be run.
LineHandler: Represents the method that is called when the Dialogue delivers a Line .
OptionsHandler: Represents the method that is called when the Dialogue delivers an OptionSet .
CommandHandler: Represents the method that is called when the Dialogue delivers a Command .
NodeStartHandler: Represents the method that is called when the Dialogue begins executing a node.
NodeCompleteHandler: Represents the method that is called when the Dialogue reaches the end of a node.
Class in Yarn
Inherits from System.Object
A type that represents functions.
Functions have parameters and a return type, and can be called from script. Instances of this type are created when the host application registers new functions (such as through using the RegisterFunction(string,Delegate) methods or similar.)
Name | Description |
---|---|
Gets a more verbose description of this type.
Gets the collection of methods that are available on this type.
Gets the name of this type.
Gets the list of the parameter types that this function is called with.
Gets the parent of this type.
Gets the type of value that this function returns.
Property in FunctionType
Gets the list of the parameter types that this function is called with.
The length of this list also determines the number of parameters this function accepts (also known as the function's arity ).
Interface in Yarn
Defines properties that describe a type in the Yarn language.
Name | Description |
---|---|
Gets a more verbose description of this type.
Gets the collection of methods that are available on this type.
Gets the name of this type.
Gets the parent of this type.