Expand description
A Bevy plugin for loading configuration from YAML, JSON, or RON files with environment variable overrides.
This crate provides a simple way to load configuration files into Bevy resources, with support for runtime overrides via environment variables. This is useful for game settings, input mappings, and other configurable parameters.
§Features
- Load configuration from YAML, JSON, or RON files at startup
- Format is detected automatically from the file extension in
ConfigFile::PATH - Override configuration values using environment variables (always JSON)
- Automatic resource registration with Bevy’s reflection system
- Type-safe configuration with serde deserialization
§Cargo Features
| Feature | Default | Description |
|---|---|---|
yaml | yes | YAML config support (.yaml, .yml) |
json | no | JSON config support (.json) |
ron | no | RON config support (.ron) |
logging | yes | Log config loading events |
At least one format feature must be enabled. To use multiple formats:
bevy_config_file = { version = "0.2", features = ["yaml", "json", "ron"] }§Quick Start
The format is detected from the file extension in ConfigFile::PATH.
#[derive(Resource, Reflect, Debug, Serialize, Deserialize)]
#[reflect(Resource)]
pub struct CameraSettings {
pub pan_speed: f32,
pub zoom_speed: f32,
}
impl ConfigFile for CameraSettings {
const PATH: &'static str = "assets/config/camera_settings.yaml";
}
App::new()
.add_plugins(config_file_plugin::<CameraSettings>)
.run();§Config File Formats
The same struct can be loaded from any supported format by changing the file extension:
YAML (camera_settings.yaml):
pan_speed: 1000.0
zoom_speed: 1.0JSON (camera_settings.json):
{ "pan_speed": 1000.0, "zoom_speed": 1.0 }RON (camera_settings.ron):
(pan_speed: 1000.0, zoom_speed: 1.0)§Environment Variable Overrides
You can override configuration values at runtime using environment variables. Overrides are always JSON, regardless of the config file format:
CONFIG_CameraSettings='{"pan_speed": 2000.0}' ./gameThe environment variable name is CONFIG_{TypeName} where TypeName is the last
component of the type’s fully qualified name.
Enums§
- Load
Config Error - Errors that can occur when loading configuration files.
Traits§
- Config
File - Trait for types that can be loaded from a configuration file.
Functions§
- config_
file_ plugin - Creates a Bevy plugin that loads a configuration resource from a file at startup.
- load_
config_ file - Loads configuration from a file with optional environment variable overrides.
- load_
resource_ from_ config_ file - Loads a configuration resource from a file and inserts it into Bevy’s ECS.