Godot YAML
by FimbulWorks
Godot YAML GDExtension
This is the C++ GDExtension implementation of the Godot YAML plugin. It provides high-performance YAML parsing and serialization using RapidYAML as the core engine, offering sub-millisecond processing for most YAML documents. This extension is built for Godot 4.3 or later.
๐ For full usage details and API documentation, see the plugin README:
๐ project/addons/yaml/README.md
๐ Version History
- 0.12.1 (Current) - Build support for Linux (x86 64-bit)
- 0.12.0 - Performance optimizations, bug fixes, and comprehensive tests for all variant types.
- 0.11.0 - Added support for parsing multiple documents, and error handling for custom class deserialization.
- 0.10.1 - Fixed issue with custom Resources not being serializable.
- 0.10.0 - Added custom class serialization support, upgraded to Godot 4.3.
- 0.9.0 - Initial public release.
๐ Quick Start
# Parse YAML
var result = YAML.parse("key: value\nlist:\n - item1\n - item2")
if !result.has_error():
var data = result.get_data()
print(data.key) # Outputs: value
print(data.list) # Outputs: [item1, item2]
# Generate YAML
var yaml = YAML.stringify({"numbers": [1, 2, 3]}).get_data()
print(yaml) # Outputs: "numbers:\n - 1\n - 2\n - 3\n"
# Register a custom class
class_name MyCustomClass extends RefCounted
var name = ""
var value = 0
static func from_dict(dict):
var obj = MyCustomClass.new()
obj.name = dict.get("name", "")
obj.value = dict.get("value", 0)
return obj
func to_dict():
return {"name": name, "value": value}
# In your initialization code:
YAML.register_class(MyCustomClass)
๐ฅ Key Features
- โก High Performance โ Optimized for speed with zero-copy parsing.
- ๐งฉ Full Variant Support โ Handles all* Godot built-in Variant types.
- ๐งช Custom Class Support - Register GDScript classes for serialization/deserialization.
- ๐๏ธ Resource References โ Use
!Resource
to auto-load scenes, textures, audio, and other assets viaResourceLoader
. - ๐ Multi-Document Support โ Parse YAML files with multiple
---
separated documents. - ๐จ Style Customization: Control how YAML is formatted with customizable style options with
YAMLStyle
. - ๐ Tagged Types: Support for custom YAML tags and automatic tagging of Godot types.
- ๐ก๏ธ Error Handling: Comprehensive error reporting with line and column information.
- ๐งต Thread-Safe: Fully supports multi-threaded parsing and emission without locking.
- ๐ก๏ธ Validation: Separate validation step for checking YAML syntax without full parsing.
* Except Callable or RID.
๐ ๏ธ Installation & Setup
Building From Source
Prerequisites
- Git (for cloning and submodules)
- Python 3.x (for SCons build system)
- C++ compiler with C++17 support:
- Windows: Visual Studio 2022 with C++ workload
- Linux/macOS: GCC 9+ or Clang 10+
- SCons build system (
pip install scons
)
Step 1: Clone the Repository
# Clone with submodules
git clone --recursive https://github.com/fimbul-works/godot-yaml
# Or if already cloned, initialize submodules
git submodule update --init --recursive
Step 2: Build the Extension
# Debug build
scons target=template_debug
# Release build
scons target=template_release
# Specify platform (default is platform-dependent)
scons platform=windows target=template_release
scons platform=linux target=template_release
Build Options
platform
: Target (windows
,linux
,macos
, etc.)target
: Build type (template_debug
,template_release
)arch
: CPU architecture (x86_32
,x86_64
,arm64
, etc.)dev_build
: Enable extra debugging (yes
/no
)use_llvm
: Use Clang/LLVM compiler (yes
/no
)verbose
: Verbose build output (yes
/no
)
โ Supported Platforms
- Windows: โ Prebuilt binaries available.
- Linux: โ Prebuilt binaries available for x86 64-bit architecture.
- macOS: ๐ง Not yet prebuilt, but should compile without issues.
๐ Contributions welcome! If you can help with Linux/macOS, open a PR.
โ๏ธ Error Handling in GDScript
When working with YAML, errors always return detailed messages with line/column numbers.
Example: Handling Parse Errors
var result = YAML.parse("invalid_yaml: - missing_indent")
if result.has_error():
print("โ Error:", result.get_error_message())
print("๐ Line:", result.get_error_line(), "Column:", result.get_error_column())
else:
var data = result.get_data()
print("โ
Parsed successfully:", data)
๐ See project/addons/yaml/README.md
for more examples.
๐งโ๐ป Contributing
Development Guidelines
- Follow Godot's API design patterns.
- Minimize allocations (use
ryml::cstring
instead ofstd::string
). - Error handling: Use
YAMLResult
and throwYAMLException
for C++ errors. - Thread safety: No global state; ensure safe multithreading.
- Write tests: Every new feature should have test coverage.
- Document your changes: All public APIs must be documented.
Code Formatting
# Format code (requires clang-format)
clang-format -i src/*.cpp src/*.h src/variants/*.cpp src/variants/*.h
๐ License
MIT License (see LICENSE file for details).
๐ Built with โก by FimbulWorks
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author