Yarn Spinner in Unity Scenes
Learn the various components and assets used in getting Yarn Spinner up and running Unity scenes.
Last updated
Was this helpful?
Learn the various components and assets used in getting Yarn Spinner up and running Unity scenes.
Last updated
Was this helpful?
Yarn Spinner is a powerful dialogue system for Unity that allows you to create branching narratives for your games. This guide will walk you through setting up Yarn Spinner in your Unity project and getting a basic dialogue system running.
To organize your dialogue, you'll need to create a Yarn Project:
In the Unity Editor, go to Assets > Yarn Spinner > Yarn Project
Name your new Yarn Project file (e.g., "MyGame")
The Yarn Project will appear in your Assets folder
A Yarn Project is a special file that groups related Yarn Scripts together. It's essential for using dialogue in your game.
Yarn Projects include all Yarn Scripts in the same directory by default. You can modify the Source Files setting to include scripts from different locations.
Now, let's create a Yarn Script to write your dialogue:
Go to Assets > Yarn Spinner > Yarn Script
Name your script (e.g., "Introduction")
Double-click the script to open it in the editor
Here's a simple example of dialogue written in Yarn:
Save your changes. The script will be automatically included in your Yarn Project if it's in the same folder.
When writing dialogue, remember:
Each node begins with title:
followed by the node name
The node's content starts after ---
and ends with ===
Options are created using ->
at the start of a line
Commands use <<command>>
syntax
To use your dialogue in-game, you need to add a Dialogue System to your scene:
In your scene hierarchy, right-click and select Yarn Spinner > Dialogue System
With the Dialogue System selected, locate the Dialogue Runner component in the Inspector
Drag your Yarn Project into the "Yarn Project" field in the Dialogue Runner
If you want dialogue to start automatically, check "Start Automatically" and set your starting node (usually "Start")
The Dialogue System prefab comes with several components:
Dialogue Runner: The core component that runs your dialogue
Line Presenter: Displays text dialogue to the player
Options Presenter: Shows choices for the player to select
Line Advancer: Allows the player to progress through dialogue
Dialogue Presenters (formerly called Dialogue Views) are components that display dialogue content to the player:
Line Presenter
The Line Presenter shows lines of dialogue in a text box. You can configure:
Text appearance and positioning
Character name display
Typewriter effect speed
Fading effects
Auto-advance settings
Options Presenter
The Options Presenter displays choices for the player to select. You can configure:
Option appearance and positioning
List layout
Whether to show unavailable options
Line Advancer
The Line Advancer (formerly Dialogue Advance Input) allows players to progress dialogue using input:
Select your Line Presenter in the hierarchy
Find the associated Line Advancer component
Configure the input method (keycode, button, etc.)
You can have multiple Dialogue Presenters in your scene, each handling different aspects of dialogue presentation.
Variable Storage
Variable Storage components keep track of variables in your dialogue:
By default, Yarn Spinner uses In-Memory Variable Storage (variables are lost when the game ends)
For persistent variables, create a custom Variable Storage that connects to your game's save system
To debug variables during development, use the Debug Text View property of the In-Memory Variable Storage component.
Line Providers
Line Providers fetch the content for each line of dialogue:
Text Line Provider: Provides just the text of dialogue lines
Audio Line Provider: Provides text and associated audio clips
Unity Localised Line Provider: Works with Unity's Localization system
If you don't set a Line Provider, the system will create a Text Line Provider automatically.
These components are all configured in the Dialogue Runner:
To test your dialogue system:
Make sure your Dialogue System is set up properly
Press Play in the Unity Editor
If "Start Automatically" is enabled, dialogue should begin
Otherwise, trigger dialogue by calling the StartDialogue()
method on your Dialogue Runner
For example, you might trigger dialogue when a player presses a button near an NPC:
While testing, use the Unity Console to check for any errors in your Yarn scripts.
Yarn Spinner makes it easy to add multiple languages to your game:
Select your Yarn Project in the Assets panel
Click "Export Strings as CSV" in the Inspector
Translate the exported CSV file
Import the translations back into your project
You can use either:
Built-in Localisation System: Manage translations directly through Yarn Spinner
Unity Localisation System: Integrate with Unity's Localisation package
If using Unity's Localisation:
Install the Localisation package
Check "Use Unity Localisation System" in your Yarn Project
Use the Unity Localised Line Provider with your Dialogue Runner
Extend Yarn Spinner by creating custom commands to connect dialogue with your game mechanics:
Custom Commands
Create a command that your Yarn scripts can call:
Then use it in your Yarn script:
Custom Dialogue Presenters
For unique presentation styles, create custom Dialogue Presenters by subclassing DialoguePresenterBase
:
Common issues and solutions:
Check if your Yarn Project is assigned to the Dialogue Runner
Verify that your Yarn Script contains a node with the name specified in "Start Node"
Make sure there are no compilation errors in your Yarn Scripts
Ensure the Line Presenter component is properly configured
Check that the Canvas Group and Text components are correctly assigned
Verify that your custom command method is in a MonoBehaviour that's in the scene
Make sure the method has the [YarnCommand]
attribute
Check the console for any error messages
For debugging, use the In-Memory Variable Storage's "Debug Text View" to see variable values
Make sure variables are declared with the correct type
This guide should help you get started with Yarn Spinner in Unity. For more detailed information, refer to the .