bevy_config_file
A simple Bevy plugin for loading configuration from YAML files with environment variable overrides.
Features
- Load configuration from YAML files at application startup
- Override configuration values using environment variables with JSON
- Automatic resource registration with Bevy's reflection system
- Type-safe configuration with serde deserialization
- Support for any type that implements
Resource,Deserialize,Serialize, andReflect
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
- Define your configuration struct:
use *;
use ;
use ;
- Create your YAML configuration file at
assets/config/camera_settings.yaml:
pan_speed: 1000.0
zoom_speed: 1.0
initial_height: 1000.0
- Add the plugin to your Bevy app:
- Access the configuration in your systems:
Environment Variable Overrides
You can override configuration values at runtime using environment variables. This is particularly useful for testing or debugging.
The environment variable name follows the pattern CONFIG_{TypeName} where TypeName is the last component of your type's fully qualified name.
Example
For a type my_game::config::CameraSettings, you would use:
CONFIG_CameraSettings='{"pan_speed": 2000.0}'
The JSON object should contain the fields you want to override. Only top-level fields are overridden; nested objects are replaced entirely, not merged.
Testing Use Case
This feature is especially useful in tests:
Advanced Usage
Manual Loading
If you need more control over when and how the configuration is loaded, you can use the lower-level functions:
use ;
// In a Bevy system:
// Or load without inserting into ECS:
let config = .expect;
Multiple Configuration Files
You can load multiple configuration files by creating multiple types and adding multiple plugins:
new
.add_plugins
.add_plugins
.add_plugins
.run;