Godot (GDScript)
Learn how to use Yarn Spinner for Godot (GDScript). This Quickstart is here to help you get up and running during the Alpha Period for Yarn Spinner for Godot (GDScript).
This is an Alpha release of Yarn Spinner for Godot (GDScript). There will be bugs, we might change the API or features with an update, or something may break. We do not recommend you use this to ship a game just yet.
This gets you from zero to running dialogue in about five minutes. It assumes you already know how to write Yarn, and how to use Godot.
Yarn Spinner for Godot (GDScript) requires Godot 4.6.x of higher.
Install the Plugin
Grab the plugin from https://github.com/YarnSpinnerTool/YarnSpinner-Godot-GDScript
Copy
addons/yarn_spinner/into your Godot project'saddons/directory.Go to Project > Project Settings > Plugins and enable Yarn Spinner.
Add Your Yarn Files
Make sure you have a .yarnproject and your .yarn files, then drop them into your Godot project. The .yarnproject tells the compiler which .yarn files to include.
Automatic compilation
If ysc (the Yarn Spinner Console tool) is on your system PATH, compilation is automatic. Whenever Godot imports or reimports the .yarnproject, the plugin runs ysc compile for all .yarn files in scope. Editing a .yarn file or the .yarnproject itself triggers a reimport, so you never need to compile manually.
Install ysc globally from https://github.com/yarnspinnertool/yarnspinner-console
A full release of Yarn Spinner for Godot (GDScript) will likely include ysc internally.
Manual compilation
If ysc isn't on your PATH, you can compile manually:
You can also set the path to ysc in the import options for the .yarnproject file in the Godot inspector, or in Project Settings > Yarn Spinner > YSC Path.
Set Up the Scene
Here's a minimal scene tree exmple:
YarnDialogueRunner -- add a Node, attach the
YarnDialogueRunnerscript. In the inspector, setYarn Projectto your.yarnprojectfile.LinePresenter -- add a PanelContainer, attach the
YarnLinePresenterscript. Give it aRichTextLabelchild namedTextLabelfor dialogue text, aLabelnamedCharacterLabelfor the speaker name, and optionally aLabelnamedContinueIndicator.OptionsPresenter -- add a PanelContainer, attach the
YarnOptionsPresenterscript. Give it aVBoxContainerchild namedOptionsContainer-- buttons are created automatically at runtime.
Wire It Up
In your game script, connect the presenters to the runner and start dialogue:
That's it. Run the scene and your dialogue plays.
Commands
Commands let Yarn tell your game to do things. The easiest way is the naming convention -- prefix any method with _yarn_command_ and the runner finds it automatically.
Make sure auto_discover_commands is enabled on the dialogue runner (it is by default). The runner scans the scene tree on startup and registers everything it finds.
If a command returns void, dialogue continues immediately. If it returns a Signal, dialogue pauses until that signal fires.
Instance Commands
For commands that target specific nodes (like <<move mae center>>), define the method on the node's class:
Register the class as an instance command source:
Now <<move mae center>> finds the node named "mae", checks it's a Character, and calls _yarn_command_move("center") on it.
Functions
Functions let Yarn read values from your game. Register them with a name and parameter count:
Use them in Yarn expressions:
Or use the naming convention with _yarn_function_ prefix for auto-discovery.
Variables
Yarn variables work automatically. Declare them in your .yarn files and they're stored in an in-memory dictionary:
Access them from GDScript:
The runner creates a YarnInMemoryVariableStorage automatically. If you need persistence, subclass YarnVariableStorage and assign it in the inspector.
Signals
The dialogue runner emits signals for lifecycle events:
Useful Settings
On the YarnDialogueRunner in the inspector:
Start Node -- which Yarn node to begin from (default:
"Start")Auto Start -- begin dialogue when the scene loads
Run Selected Option As Line -- after the player picks an option, show it as a line of dialogue before continuing
Auto Discover Commands -- scan the scene tree for
_yarn_command_*and_yarn_function_*methods
On YarnLinePresenter:
Typewriter Mode --
INSTANT,LETTER(character by character), orWORDCharacters Per Second / Words Per Second -- typewriter speed
Auto Advance -- automatically continue after a delay
Use Markup -- enable BBCode rendering in the text label
On YarnOptionsPresenter:
Hide Unavailable -- hide options the player can't pick (vs showing them greyed out)
Custom Presenters
To make your own persenter UI subclass YarnDialoguePresenter:
Register it the same way:
Node Groups and Saliency
If you're using node groups (multiple versions of the same content with when: conditions), set a saliency strategy on the runner:
Available strategies: YarnFirstSaliencyStrategy, YarnBestSaliencyStrategy, YarnRandomSaliencyStrategy, YarnBestLeastRecentlyViewedSaliencyStrategy, YarnRandomBestLeastRecentlyViewedSaliencyStrategy.
Last updated
Was this helpful?
