docs/bevy/examples/asset/hot_asset_reloading.rs 1.3 K · 37 lines · raw · history
| 1 | //! Hot reloading allows you to modify assets files to be immediately reloaded while your game is |
| 2 | //! running. This lets you immediately see the results of your changes without restarting the game. |
| 3 | //! This example illustrates hot reloading mesh changes. |
| 4 | //! |
| 5 | //! Note that hot asset reloading requires the [`AssetWatcher`](bevy::asset::io::AssetWatcher) to be enabled |
| 6 | //! for your current platform. For desktop platforms, enable the `file_watcher` cargo feature. |
| 7 | |
| 8 | use bevy::prelude::*; |
| 9 | |
| 10 | fn main() { |
| 11 | App::new() |
| 12 | .add_plugins(DefaultPlugins) |
| 13 | .add_systems(Startup, setup) |
| 14 | .run(); |
| 15 | } |
| 16 | |
| 17 | fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { |
| 18 | // Load our mesh: |
| 19 | let scene_handle = |
| 20 | asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/torus/torus.gltf")); |
| 21 | |
| 22 | // Any changes to the mesh will be reloaded automatically! Try making a change to torus.gltf. |
| 23 | // You should see the changes immediately show up in your app. |
| 24 | |
| 25 | // mesh |
| 26 | commands.spawn(WorldAssetRoot(scene_handle)); |
| 27 | // light |
| 28 | commands.spawn(( |
| 29 | DirectionalLight::default(), |
| 30 | Transform::from_xyz(4.0, 5.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y), |
| 31 | )); |
| 32 | // camera |
| 33 | commands.spawn(( |
| 34 | Camera3d::default(), |
| 35 | Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y), |
| 36 | )); |
| 37 | } |