⚡Bevy Quick Start
Quickly get started with a simple scene.
We will now go through the steps to setup a new Bevy project running Yarn Spinner dialogues
Setting up the crate
Run the following in your terminal to create a new crate with the required dependencies:
The dependency bevy_yarnspinner
is for the Yarn Spinner Bevy plugin proper, while bevy_yarnspinner_example_dialogue_view
gives us a nice default Dialogue View, so we can actually see the text we've written and have options to click on.
Adding the Yarn Files
We'll use a single Yarn file for this example. Inside the folder assets/dialogue
, add a file named example.yarn
with the following content:
You can learn about our recommended editor, Visual Studio Code with the official Yarn Spinner Extension at: Editing with VS Code.
The main code
Add the following code to your src/main.rs
.
Reiterating the comments in the code, let's take a look at some snippets.
This self-explanatory line initializes the plugin. When using the standard constructor with no options, Yarn files will be searched for in the directory <your game>/assets/dialogue/
, where all files ending in .yarn
will be compiled as soon as the game starts.
The plugin makes sure all components of Yarn Spinner work except for any actual graphics. You need to instantiate a Dialogue View for that:
Here we initialize the dialogue view shipped by the bevy_yarnspinner_example_dialogue_view
crate. It offers some sensible defaults which you can see in the screenshots used throughout this guide. You can of course skip this and use your own dialogue view instead.
The method .run_if(resource_added::<YarnProject>()
is our way of saying "run this system once as soon as our Yarn files are done compiling". Let's look at what will actually be run in that moment:
The main way of interacting with Yarn files during runtime and managing the flow of a dialog is through a DialogueRunner
. To do this, we use the YarnProject
resource we referenced in the run_if
section above. It represents our compiled Yarn files, which we use to create a new dialog runner.
We then point it to the node named "Start" of our Yarn file. We use start_node
for this, which will "move" the dialog runner to the provided node and start executing the dialog in the next frame, using the registered Dialogue View to actually present it on the screen.
Finally, we spawn the dialog runner on an own entity into the Bevy world.
In the end, your file structure should look like this:
Run your game with cargo run
and you should see the following:
Last updated