Yarn Spinner 3.3

Yarn Spinner 3.3 makes the compiler stricter about functions, lets commands and functions take as long as they need, and makes definitions files easier to share between your game and VS Code. It’s out for Unity, Godot (GDScript), VS Code and ysc.

Functions Must Be Declared

The compiler now needs to know about every function your scripts call. Before 3.3, it tried to work out a function’s types from how you used it. That guess could be wrong, and it didn’t work inside lines.

Your engine declares your functions for you. Unity adds the functions you write to a definitions file each time your C# scripts compile, and Godot does the same each time a Yarn Project imports. If a script calls a function nothing declares, the project won’t compile, and you’ll see error YS0013, “no declaration found”.

Projects made before Yarn Spinner 3.3 keep working. In those, an undeclared function is a warning (YS0065), and the project’s Inspector offers to upgrade it. Some 3.3 features need the upgrade. See Functions.

Better Definitions Files

Definitions files (.ysls.json) list your game’s commands and functions, so VS Code can suggest and check them, and so the compiler knows your functions. In 3.3, a Yarn Project’s definitions list can:

  • list several files.
  • use * wildcards, as in "definitions/*.ysls.json".
  • start a path with ${workspaceRoot}, which stands for your game project’s folder. Unity, Godot, Unreal, VS Code and ysc all understand it, so the path keeps working when you move the Yarn Project.

New Unity projects list ${workspaceRoot}/ProjectSettings/Packages/dev.yarnspinner/**/*.ysls.json from the start. VS Code checks each definitions file for problems, and offers a quick fix that attaches a definitions file when a function is undeclared. See Definitions.

Functions Can Wait

A function can now take as long as it needs to return a value. In Unity, a function can return an awaitable type. In Godot, a function can use await. The dialogue pauses until the function returns. This is useful for things like asking the player to pick an item.

Commands and Functions Can Be Cancelled

If the last parameter of a command or function is a cancellation token, Yarn Spinner passes one in. It’s cancelled when the command or function should stop early, for example when the player skips ahead. In Unity, use a CancellationToken or a LineCancellationToken. In Godot, use a YarnCancellationToken.

Your Own Types as Parameters

Commands and functions can take your own types as parameters. Write a converter that turns the text in your script into your type, and Yarn Spinner calls it for you. In Unity, mark a static method with the YarnConverter attribute. In Godot, use add_converter() on the Dialogue Runner.

[YarnConverter(typeof(Tool))]
public static bool TryGetTool(string input, out Tool value)
{
    value = FindTool(input);
    return value != null;
}

[YarnCommand("dig")]
public static void Dig(Tool tool)
{
    tool.Durability--;
}
A Unity command that takes a Tool.

Presenter Methods Are Optional

In Unity, the methods on DialoguePresenterBase are now virtual. A custom Presenter only needs the methods it uses, and the rest do nothing.

OnDialogueStartedAsync and OnDialogueCompleteAsync now take a CancellationToken. The versions without one are obsolete and are no longer called. If your Presenter overrides them, add the parameter.

Lambdas Are Deprecated

Registering a command or function with a lambda is deprecated in Unity and Godot. Lambdas are slower and aren’t cleaned up automatically. Pass a named method instead.

Clusters in the Graph View

To gather nodes into a box in VS Code’s graph view, use the cluster: header. The older group: header still works, but is deprecated, so it isn’t confused with node groups.

Other Changes

  • Node pickers can be filtered. In Unity, add a filter to a [YarnNode] attribute to limit which nodes appear in the Inspector. Godot’s node pickers can be filtered too.
  • Godot can compile from the Yarn Spinner screen. The new Compile button saves the open file and compiles its Yarn Project.
  • Yarn Spinner as a library is async. If you use the core library directly, Dialogue now talks to your game through an IDialogueResponder, and returns tasks. This is a breaking change for library users.
  • ysc reads every definitions file in a Yarn Project, in the current format.

For every change, see the changelogs for Yarn Spinner, Yarn Spinner for Unity and the Changelog page.