EasyYamlParser Quick Start

Complete a YAML read/write run with EasyYamlParser: load a YAML string, read values, build new YAML, and print it.

This page walks through loading a YAML string, reading values out of it, then creating new YAML and printing it as a string.

Prerequisites

  • Setup is complete and EasyYamlParser is enabled in the project.
  • You can create Blueprint variables and connect nodes.

Blueprint outline

The flow built in this quick start is:

  1. Parse a YAML string with Load Yaml From String and store the Yaml Object in a variable.
  2. Read values with Read String and Read Int, and show them with Print String.
  3. Create new YAML with Create Empty Yaml Object and write values with the Write nodes.
  4. Convert the result to a string with Yaml To String and check it.

1. Create an Actor Blueprint

In the Content Browser, create a Blueprint Class with Actor as its parent. Name it BP_YamlSample.

Open the Event Graph and lay out nodes starting from Event BeginPlay.

2. Create a Yaml Object with Load Yaml From String

Create a Yaml Object from a YAML string. Add a Load Yaml From String node and enter the following YAML into the Yaml String pin.

player:
  name: Hero
  level: 10

Insert a Branch node so the following steps run only when Success is true. On failure, print the Error Message with Print String. The message carries the line and column numbers of the syntax error, which tells you exactly which line of the YAML to fix.

Store the returned Yaml Object in a variable. Create a variable LoadedYaml (type: Yaml Object struct) and save it with a SET node. The Read nodes take this Yaml Object pin as their input.

Example Blueprint loading a YAML string with Load Yaml From String

3. Read the player name with Read String

Add a Read String node with the following inputs.

Pin Value
Yaml Object LoadedYaml
Access String player.name
Default Value Unknown

The access string player.name points at name inside the player map of the YAML. When the path is missing — or the value is not a string — the Default Value (Unknown) is returned instead.

4. Read the level with Read Int and print it

Add a Read Int node with Access String set to player.level and Default Value set to 1. Connect LoadedYaml to its Yaml Object pin as well.

Combine both results for display. Use an Append node to join the Read String result and the Read Int result converted with To String, then feed it into Print String.

Example Blueprint reading YAML values with Read String and Read Int

When you play, the output log shows something like Hero 10. If it does not, see When something goes wrong.

5. Create YAML with Create Empty Yaml Object and write to it

Next, create new YAML. Store the return value of Create Empty Yaml Object in a variable NewYaml.

Write values with the Write nodes. Each execution adds a value to the Yaml Object, so run them in order with a Sequence node.

Node Access String Value
Write Int score 1000
Write Float time 45.5
Write String playerName Hero
Write Bool isActive checked
Example Blueprint writing values into YAML with the Write nodes

When you specify a hierarchical access string such as player.stats.level, the intermediate maps are created automatically if they do not exist.

6. Check the content with Yaml To String

Convert the content of NewYaml to a string with the Yaml To String node. Because YAML expresses hierarchy with indentation, the output is always formatted with line breaks and indentation.

Printing the result with Print String shows the following YAML string.

score: 1000
time: 45.5
playerName: Hero
isActive: true
Example Blueprint converting YAML to a string with Yaml To String

To save it to a file, use the Save Yaml To File node. See Creating save data in the Use Cases page.

When something goes wrong

Symptom What to check
Success stays false Whether Yaml String is valid YAML (indentation depth, whitespace after colons, quoting)
Error Message reports a line number Check the line at the line X column Y position included in the message
Error Message says File not found The File Path and Is Absolute pins of Load Yaml From File (relative paths are Content-based)
Values keep coming back as the default The spelling and hierarchy of the access string (is player.name written as playerName?)