//! This example demonstrates the hot-reloading capabilities of prototypes.
//!
//! It's pretty easy to enable hot-reloading in Bevy— just enable [`AssetPlugin::watch_for_changes`].
//! This allows changes to any prototype to be automatically picked up.
//!
//! This example also uses the [`ProtoAssetEvent`] event to reload an existing entity if
//! its prototype changes, which can allow for faster development.
//!
//! Please note that hot-reloading is far from perfect.
//! Changing the IDs of a prototype or its hierarchical structure may cause the
//! reload to fail or work unexpectedly upon prototype re-registration.
//! However, it can still be a great tool to use for fast prototyping.
//!
//! Just run the example and try it out for yourself!
use bevy::asset::ChangeWatcher;
use bevy::prelude::*;
use std::time::Duration;
use bevy_proto::prelude::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(AssetPlugin {
// Enable hot-reloading of assets:
watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)),
..default()
}),
ProtoPlugin::new(),
))
.add_systems(Startup, (setup, load))
.add_systems(
Update,
(spawn.run_if(prototype_ready("ReloadableSprite")), inspect),
)
.run();
}
fn load(mut prototypes: PrototypesMut) {
prototypes.load("examples/hot_reload/ReloadableSprite.prototype.ron");
}
fn spawn(
mut commands: ProtoCommands,
keyboard_input: Res>,
mut previous: Local