diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index 3b1e2815c61ba..46b2a0f5502e3 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -79,7 +79,16 @@ pub struct AssetServerInternal { /// /// The asset server is the primary way of loading assets in bevy. It keeps track of the load state /// of the assets it manages and can even reload them from the filesystem with -/// [`AssetServer::watch_for_changes`]! +/// ``` +/// # use bevy_asset::*; +/// # use bevy_app::*; +/// # let mut app = App::new(); +/// // AssetServerSettings must be inserted before adding the AssetPlugin or DefaultPlugins. +/// app.insert_resource(AssetServerSettings { +/// watch_for_changes: true, +/// ..Default::default() +/// }); +/// ``` /// /// The asset server is a _resource_, so in order to access it in a system you need a `Res` /// accessor, like this: @@ -169,13 +178,6 @@ impl AssetServer { loaders.push(Arc::new(loader)); } - /// Enable watching of the filesystem for changes, if support is available, starting from after - /// the point of calling this function. - pub fn watch_for_changes(&self) -> Result<(), AssetServerError> { - self.asset_io().watch_for_changes()?; - Ok(()) - } - /// Gets a strong handle for an asset with the provided id. pub fn get_handle>(&self, id: I) -> Handle { let sender = self.server.asset_ref_counter.channel.sender.clone(); diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index f57e2d0123409..24e9d975b1193 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -29,7 +29,9 @@ mod path; /// The `bevy_asset` prelude. pub mod prelude { #[doc(hidden)] - pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped}; + pub use crate::{ + AddAsset, AssetEvent, AssetServer, AssetServerSettings, Assets, Handle, HandleUntyped, + }; } pub use anyhow::Error; diff --git a/examples/scene/scene.rs b/examples/scene/scene.rs index ecf7a04acf268..bb4218d0ccbc8 100644 --- a/examples/scene/scene.rs +++ b/examples/scene/scene.rs @@ -6,6 +6,13 @@ use bevy::{prelude::*, tasks::IoTaskPool, utils::Duration}; fn main() { App::new() + // This tells the AssetServer to watch for changes to assets. + // It enables our scenes to automatically reload in game when we modify their files. + // AssetServerSettings must be inserted before the DefaultPlugins are added. + .insert_resource(AssetServerSettings { + watch_for_changes: true, + ..default() + }) .add_plugins(DefaultPlugins) .register_type::() .register_type::() @@ -65,10 +72,6 @@ fn load_scene_system(mut commands: Commands, asset_server: Res) { scene: asset_server.load(SCENE_FILE_PATH), ..default() }); - - // This tells the AssetServer to watch for changes to assets. - // It enables our scenes to automatically reload in game when we modify their files - asset_server.watch_for_changes().unwrap(); } // This system logs all ComponentA components in our world. Try making a change to a ComponentA in diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index efe6d6fd7d814..b085f971eef4c 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -8,7 +8,7 @@ use bevy::{ prelude::*, reflect::TypeUuid, render::{ - camera::{Camera, RenderTarget}, + camera::RenderTarget, render_resource::{ AsBindGroup, Extent3d, ShaderRef, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, @@ -20,13 +20,12 @@ use bevy::{ }; fn main() { - let mut app = App::new(); - app.add_plugins(DefaultPlugins) + App::new() + .add_plugins(DefaultPlugins) .add_plugin(Material2dPlugin::::default()) .add_startup_system(setup) - .add_system(main_camera_cube_rotator_system); - - app.run(); + .add_system(main_camera_cube_rotator_system) + .run(); } /// Marks the first camera cube (rendered to a texture.) @@ -40,11 +39,8 @@ fn setup( mut post_processing_materials: ResMut>, mut materials: ResMut>, mut images: ResMut>, - asset_server: Res, ) { - asset_server.watch_for_changes().unwrap(); - - let window = windows.get_primary_mut().unwrap(); + let window = windows.primary_mut(); let size = Extent3d { width: window.physical_width(), height: window.physical_height(), diff --git a/examples/shader/shader_instancing.rs b/examples/shader/shader_instancing.rs index 8f9d9b7888326..8744d9b0eec0e 100644 --- a/examples/shader/shader_instancing.rs +++ b/examples/shader/shader_instancing.rs @@ -168,7 +168,6 @@ pub struct CustomPipeline { impl FromWorld for CustomPipeline { fn from_world(world: &mut World) -> Self { let asset_server = world.resource::(); - asset_server.watch_for_changes().unwrap(); let shader = asset_server.load("shaders/instancing.wgsl"); let mesh_pipeline = world.resource::(); diff --git a/examples/tools/scene_viewer.rs b/examples/tools/scene_viewer.rs index e27f38223261c..2ba8d272fa0d0 100644 --- a/examples/tools/scene_viewer.rs +++ b/examples/tools/scene_viewer.rs @@ -5,7 +5,7 @@ //! With no arguments it will load the `FieldHelmet` glTF model from the repository assets subdirectory. use bevy::{ - asset::{AssetServerSettings, LoadState}, + asset::LoadState, gltf::Gltf, input::mouse::MouseMotion, math::Vec3A,