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).

triangle-exclamation

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.

circle-info

Yarn Spinner for Godot (GDScript) requires Godot 4.6.x of higher.

circle-check

Install the Plugin

Grab the plugin from https://github.com/YarnSpinnerTool/YarnSpinner-Godot-GDScriptarrow-up-right

  1. Copy addons/yarn_spinner/ into your Godot project's addons/ directory.

  2. 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-consolearrow-up-right

circle-info

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:

  1. YarnDialogueRunner -- add a Node, attach the YarnDialogueRunner script. In the inspector, set Yarn Project to your .yarnproject file.

  2. LinePresenter -- add a PanelContainer, attach the YarnLinePresenter script. Give it a RichTextLabel child named TextLabel for dialogue text, a Label named CharacterLabel for the speaker name, and optionally a Label named ContinueIndicator.

  3. OptionsPresenter -- add a PanelContainer, attach the YarnOptionsPresenter script. Give it a VBoxContainer child named OptionsContainer -- 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), or WORD

  • Characters 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?