Crate bevy_proto

source ·
Expand description

Serializable entity configuration for the Bevy game engine.

This crate provides several abstractions for specifying serializable entities and components:


Define a serialized prototype:

# assets/prototypes/simple-enemy.yaml
name: "Simple Enemy"
    - type: Enemy
    - type: Attack
        damage: 10

Implement ProtoComponent for the component types:

use bevy::prelude::*;
use bevy_proto::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, ProtoComponent, Component)]
struct Enemy;

#[derive(Clone, Serialize, Deserialize, ProtoComponent, Component)]
struct Attack {
    damage: u16

Add the plugin:

use bevy::prelude::*;
use bevy_proto::prelude::*;

fn main() {
        .add_plugin(ProtoPlugin {
            options: Some(ProtoDataOptions {
               // You can also change the prototype directories here
               directories: vec![String::from("assets/prototypes")],
               // And specify whether you want the prototype files to be recursively loaded
               recursive_loading: false,
               // You can also update the allowed extensions within those directories
               extensions: Some(vec!["yaml", "json"]),

Finally, spawn a prototype with a system:

use bevy::prelude::*;
use bevy_proto::prelude::*;

fn spawn_enemy(mut commands: Commands, data: Res<ProtoData>, asset_server: Res<AssetServer>) {
    let proto = data.get_prototype("Simple Enemy").expect("Prototype doesn't exist!");

    // Spawns in our "Simple Enemy" Prototype
    proto.spawn(&mut commands, &data, &asset_server);


  • Provides resource and deserialization for prototype data.
  • Includes all public types and the macro to derive ProtoComponent.


  • Inserts resources for loading prototypes.
  • The default prototype object, providing the basics for the prototype system.


  • Specifies how a type inserts components into an entity.
  • Allows access to a prototype’s name and components so that it can be spawned in


Derive Macros

  • Automatically implements ProtoComponent for the given struct or enum. This works on all structs and enums, including tuple and unit structs.