Skip to main content

Yarn Script

Yarn script contains the actual story dialogue, and choices.

Steps:

  1. Navigate to your story's chapters folder in Assets/_Main/Story/Content/[your_story]/chapters
  2. Right-click and select Create > Yarn Spinner > Yarn Script
    Create Yarn Script
  3. Name the file using your chapter title (no spaces - use underscores instead)
    Eg: chapter_1, chapter_11
  4. To edit the Yarn file, you need to open it in Visual Studio Code (VS Code). \
    • Open VS Code
    • In VS Code, go to File > Open Folder...
    • Navigate to your Unity project folder and select it
    • In VS Code's Explorer panel, navigate to Assets/_Main/Story/Content/[your_story]/chapters
    • Click on your Yarn file to open it for editing Open Yarn File in VS Code
  5. Write your story content using Yarn syntax (this will be covered in the next section)
    Eg: (you can copy and paste this example into your Yarn script file)
    chapter_1.yarn
    title: Start
    ---
    Welcome to the story!
    -> Go to the next part
    ===
    title: NextPart
    ---
    This is the next part of the story.
    -> End the story
    ===
    title: End
    ---
    The end. Thanks for playing!
    ===
  6. Save the file in Visual Studio Code (Ctrl+S or Cmd+S)
  7. Return to Unity Editor
  8. To link the chapter you have just created to your story, you need to add chapter into the Story Metadata file you created earlier.
    • Navigate to your story's Metadata folder in Assets/_Main/Story/Metadata
    • Click on your Story Metadata file to view it in the Inspector panel
    • In the Chapters field, click the + button to add a new entry
    • Write the title of the chapter.
      Add Yarn File to Story Metadata
  9. Your Yarn file script is now part of your story content.