#yarn #spinner #dialog #macro #bevy #friendly #yarnspinner

macro yarnspinner_macros

Macros for Yarn Spinner for Rust, the friendly tool for writing game dialogue

1 unstable release

0.1.0 Jan 30, 2024

#2182 in Game dev

Download history 31/week @ 2024-01-27 39/week @ 2024-02-03 53/week @ 2024-02-10 64/week @ 2024-02-17 149/week @ 2024-02-24 243/week @ 2024-03-02 127/week @ 2024-03-09 138/week @ 2024-03-16 345/week @ 2024-03-23 189/week @ 2024-03-30 120/week @ 2024-04-06 148/week @ 2024-04-13 245/week @ 2024-04-20

746 downloads per month
Used in 9 crates (via yarnspinner_core)


67 lines

Yarn Spinner for Rust

Crates.io Docs Discord

Note: Yarn Spinner for Rust is a work-in-progress project. We don't currently offer any official support for it. We encourage you to file issues if you have them, and to join the official Yarn Spinner Discord to discuss the project!

The Rust port of Yarn Spinner, the friendly tool for writing game dialogue. Read more on docs.yarnspinner.dev or check out the live demo, which was written using the Bevy engine. This project offers first class support for Bevy and assumes you are using it. If you are not, check out the relevant section of the book

Yarn Spinner for Rust Demo


Taken straight from our examples:

First, let's add our dependencies:

cargo add bevy bevy_yarnspinner bevy_yarnspinner_example_dialogue_view

Now, the main.rs:

use bevy::prelude::*;
use bevy_yarnspinner::prelude::*;
use bevy_yarnspinner_example_dialogue_view::prelude::*;

fn main() {
    let mut app = App::new();
        // Register the Yarn Spinner plugin using its default settings, which will look for Yarn files in the "dialogue" folder.
        // If this app should support Wasm or Android, we cannot load files without specifying them, so use the following instead.
        // YarnSpinnerPlugin::with_yarn_source(YarnFileSource::file("dialogue/hello_world.yarn")),
        // Initialize the bundled example UI
    .add_systems(Startup, setup_camera)
        // Spawn the dialogue runner once the Yarn project has finished compiling

fn setup_camera(mut commands: Commands) {

fn spawn_dialogue_runner(mut commands: Commands, project: Res<YarnProject>) {
    // Create a dialogue runner from the project.
    let mut dialogue_runner = project.create_dialogue_runner();
    // Immediately start showing the dialogue to the player

And finally, the assets/dialogue/hello_world.yarn:

title: HelloWorld
Hello World! To continue the dialogue, click with your mouse, press the space bar or the enter key.
These are options. You can select one by clicking on it or pressing the corresponding number on your keyboard.
-> Some cool option
-> Some other cool option
Now we'll jump to another node!
<<jump AnotherNode>>


title: AnotherNode
Now, a character will talk. Notice how the upper left corner of the dialogue will show their name.
Hohenheim: Hi, I'm Jan Hohenheim, creator of Yarn Spinner for Rust. I hope you enjoy using it!
Let's set a condition. Do you prefer dogs or cats?
-> Dogs
    <<set $animal = "dog">>
-> Cats
    <<set $animal = "cats">>
-> Turtles
    I, uuuh... okay, why not.
    <<set $animal = "turtles">>
Now let's print the result of the condition. Your preference is...
(Drum roll)
<<if $animal == "dog">>
Dogs! Arf Arf!
<<elseif $animal == "cats">>
Cats! (Can't say I agree, but you do you)
Turtles! Solid choice.
Et voilà! That was all. Thanks for checking out Yarn Spinner for Rust! Continuing from the last node will exit the dialogue.

Version Table

Bevy Yarn Spinner for Rust
0.13 0.2
0.12 0.1


Taken from https://github.com/bevyengine/bevy/blob/fe852fd0adbce6856f5886d66d20d62cfc936287/crates/bevy_utils/macros/src/lib.rs


~17K SLoC