2.4 (Current)
Search
⌃K
Links

Yarn Spinner for Godot

The third step in our beginner's guide, focusing on getting up and running with Yarn Spinner for Godot.
Yarn Spinner for Godot is a Yarn Labs project. It is not fully, or officially supported, and may break, or change at any time.
This step of the beginner's guide helps you move from writing Yarn scripts outside of a game engine, to initial integration steps to turn them into a game with Godot
First, launch Godot 4.1 (C# version) and create a new project.

Installing Yarn Spinner for Godot

Download a copy of the latest version of Yarn Spinner for Godot from the GitHub repository, or clone the repository somewhere.
Locate the addons/ directory in your new local copy of Yarn Spinner for Godot:
The addons directory in a local copy of Yarn Spinner for Godot.
Put a copy of this directory into your new Godot project, either by dragging the folder in your file manager (e.g. Finder or Explorer) into the folder of the Godot project, or by dragging from your file manager into the FileSystem dock of your Godot project:
The FileSystem dock in Godot, after dragging the addons directory in.
Next, choose the Project menu -> Tools -> C# -> Create C# solution. This will create a C# project for you. We have to do this to trigger the creation of the .csproj file, which is necessary to let Godot know about the Yarn Spinner plugin.
Next, open the project folder in Visual Studio Code. In the sidebar of VS Code, the .csproj file and add the following line to it, inside the <Project> </Project> tags, but not inside an <ItemGroup> or <PropertyGroup>:
<Import Project="addons\YarnSpinner-Godot\YarnSpinner-Godot.props" />
Your brand new project should look something like this in VSCode:
The .csproj for your project.
Save the tweaked .csproj file and return to Godot, everything is almost ready to go. Click the Build button in the very top right-hand corner of the Godot window. This will trigger a build of the C# solution for the project, which is required to make Godot aware of Yarn Spinner for Godot.
Once the build is complete, open the Project menu -> Project Settings, change to the Plugins tab, and tick the enabled box next to the Yarn Spinner for Godot plugin:
The Project Settings, showing the Plugins tab.
With that, you're ready to go!

Using Yarn Spinner for Godot

In your Godot project, click the Instantiate Child Scene button:
The chain-link button, for instantiating a child scene.
And navigate into the addons/YarnSpinner-Godot/Scenes folder of your project, and choose the DefaultDialogueSystem.tscn file as the scene to instantiate:
Choosing the provided DefaultDialogueSystem.tscn.
Your Scene dock will look like this showing a node hierarchy that's entirely based on the DefaultDialogueSystem.tscn scene that you instantiated:
The DefaultDialogueSystem instantiated into your scene.
You could also instantiate the DefaultDialogueSystem.tscn into your scene at a lower part of the hierarchy, instead of the root node, to display dialogue using the provided default UI, instead.
Next, create a new Yarn Project by right-clicking in the FileSystem dock, and choosing Resource...:
Creating a new Resource in the FileSystem dock.
Then filter to the YarnProject resource type, and click the Create button:
Creating a new YarnProject resource.
Name the new Yarn Project FirstProject.tres.
Next, create a new Yarn script (a file with a .yarn extension) by right-clicking in the FileSystem dock, and choosing New TextFile:
Creating a new TextFile, in order to add a Yarn script.
In the resulting New Text File... window, select All Files (*) from the dropdown in the corner, set the File name to MyStory.yarn, and click the Save button:
Naming the file for a new Yarn script.
It may take a moment, but Godot will import your new .yarn file, and it will appear in the FileSystem dock. When it's appeared, double-click on the Yarn Project, FirstProject.tres in the FileSystem dock and look to the Inspector, making sure that res://MyStory.yarn is in the list of Source Scripts, which are the Yarn scripts that compromise the new project:
The Yarn Project, with the Yarn script identified as a Source Script.
Next, open the MyStory.yarn file in VS Code, and add the following Yarn script to it, before saving it and returning to Godot:
MyStory.yarn
title: Start
tags:
---
Narrator: Oh, hello!
-> Hi, where am I?
Narrator: You're in Godot!
-> Oh.
<<jump Oh>>
-> How did I get here?
<<jump Godot>>
===
​
title: Oh
---
Narrator: Yeah, fun, right?
===
​
title: Godot
---
Narrator: Someone read the Beginner's Guide!
===
Select the the DialogueRunner node in the Scene dock, and look to the Inspector. Assign the Yarn Project you created to the DialogueRunner by dragging the FirstProject.tres Yarn Project from the FileSystem dock into the Yarn Project slot of the Inspector:
The new Yarn Project resource assigned as the Yarn Project for the DialogueRunner.
Finally, enter Start as the Start Node, and tick the box next to Starts Automatically:
Setting the Start Node, and that we want this DialogueRunner to start automatically.
Save your scene as Demo.tscn, and run the game. At this point, you can play your project, and step through the dialogue in the default Yarn Spinner for Godot Line View and Options List View:

Next steps with Yarn Spinner for Godot

With that, we've reached the end of our beginner's guide. You're ready go forth and build games with Yarn Spinner! You're also equipped to work with the rest of the documentations here! Don't forget to join the Discord to chat with other Yarn Spinner users, the Yarn Spinner team, seek help, and share your work.
Last modified 1mo ago