Skip to content

Commit 256c895

Browse files
tim-blackbirdjames7132
authored andcommitted
Remove AssetServer::watch_for_changes() (bevyengine#5968)
# Objective `AssetServer::watch_for_changes()` is racy and redundant with `AssetServerSettings`. Closes bevyengine#5964. ## Changelog * Remove `AssetServer::watch_for_changes()` * Add `AssetServerSettings` to the prelude. * Minor cleanup. ## Migration Guide `AssetServer::watch_for_changes()` was removed. Instead, use the `AssetServerSettings` resource. ```rust app // AssetServerSettings must be inserted before adding the AssetPlugin or DefaultPlugins. .insert_resource(AssetServerSettings { watch_for_changes: true, ..default() }) ``` Co-authored-by: devil-ira <justthecooldude@gmail.com>
1 parent ac6e0d8 commit 256c895

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

crates/bevy_asset/src/asset_server.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ pub struct AssetServerInternal {
7979
///
8080
/// The asset server is the primary way of loading assets in bevy. It keeps track of the load state
8181
/// of the assets it manages and can even reload them from the filesystem with
82-
/// [`AssetServer::watch_for_changes`]!
82+
/// ```
83+
/// # use bevy_asset::*;
84+
/// # use bevy_app::*;
85+
/// # let mut app = App::new();
86+
/// // AssetServerSettings must be inserted before adding the AssetPlugin or DefaultPlugins.
87+
/// app.insert_resource(AssetServerSettings {
88+
/// watch_for_changes: true,
89+
/// ..Default::default()
90+
/// });
91+
/// ```
8392
///
8493
/// The asset server is a _resource_, so in order to access it in a system you need a `Res`
8594
/// accessor, like this:
@@ -169,13 +178,6 @@ impl AssetServer {
169178
loaders.push(Arc::new(loader));
170179
}
171180

172-
/// Enable watching of the filesystem for changes, if support is available, starting from after
173-
/// the point of calling this function.
174-
pub fn watch_for_changes(&self) -> Result<(), AssetServerError> {
175-
self.asset_io().watch_for_changes()?;
176-
Ok(())
177-
}
178-
179181
/// Gets a strong handle for an asset with the provided id.
180182
pub fn get_handle<T: Asset, I: Into<HandleId>>(&self, id: I) -> Handle<T> {
181183
let sender = self.server.asset_ref_counter.channel.sender.clone();

crates/bevy_asset/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ mod path;
2929
/// The `bevy_asset` prelude.
3030
pub mod prelude {
3131
#[doc(hidden)]
32-
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
32+
pub use crate::{
33+
AddAsset, AssetEvent, AssetServer, AssetServerSettings, Assets, Handle, HandleUntyped,
34+
};
3335
}
3436

3537
pub use anyhow::Error;

examples/scene/scene.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ use bevy::{prelude::*, tasks::IoTaskPool, utils::Duration};
66

77
fn main() {
88
App::new()
9+
// This tells the AssetServer to watch for changes to assets.
10+
// It enables our scenes to automatically reload in game when we modify their files.
11+
// AssetServerSettings must be inserted before the DefaultPlugins are added.
12+
.insert_resource(AssetServerSettings {
13+
watch_for_changes: true,
14+
..default()
15+
})
916
.add_plugins(DefaultPlugins)
1017
.register_type::<ComponentA>()
1118
.register_type::<ComponentB>()
@@ -65,10 +72,6 @@ fn load_scene_system(mut commands: Commands, asset_server: Res<AssetServer>) {
6572
scene: asset_server.load(SCENE_FILE_PATH),
6673
..default()
6774
});
68-
69-
// This tells the AssetServer to watch for changes to assets.
70-
// It enables our scenes to automatically reload in game when we modify their files
71-
asset_server.watch_for_changes().unwrap();
7275
}
7376

7477
// This system logs all ComponentA components in our world. Try making a change to a ComponentA in

examples/shader/post_processing.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bevy::{
88
prelude::*,
99
reflect::TypeUuid,
1010
render::{
11-
camera::{Camera, RenderTarget},
11+
camera::RenderTarget,
1212
render_resource::{
1313
AsBindGroup, Extent3d, ShaderRef, TextureDescriptor, TextureDimension, TextureFormat,
1414
TextureUsages,
@@ -20,13 +20,12 @@ use bevy::{
2020
};
2121

2222
fn main() {
23-
let mut app = App::new();
24-
app.add_plugins(DefaultPlugins)
23+
App::new()
24+
.add_plugins(DefaultPlugins)
2525
.add_plugin(Material2dPlugin::<PostProcessingMaterial>::default())
2626
.add_startup_system(setup)
27-
.add_system(main_camera_cube_rotator_system);
28-
29-
app.run();
27+
.add_system(main_camera_cube_rotator_system)
28+
.run();
3029
}
3130

3231
/// Marks the first camera cube (rendered to a texture.)
@@ -40,11 +39,8 @@ fn setup(
4039
mut post_processing_materials: ResMut<Assets<PostProcessingMaterial>>,
4140
mut materials: ResMut<Assets<StandardMaterial>>,
4241
mut images: ResMut<Assets<Image>>,
43-
asset_server: Res<AssetServer>,
4442
) {
45-
asset_server.watch_for_changes().unwrap();
46-
47-
let window = windows.get_primary_mut().unwrap();
43+
let window = windows.primary_mut();
4844
let size = Extent3d {
4945
width: window.physical_width(),
5046
height: window.physical_height(),

examples/shader/shader_instancing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ pub struct CustomPipeline {
168168
impl FromWorld for CustomPipeline {
169169
fn from_world(world: &mut World) -> Self {
170170
let asset_server = world.resource::<AssetServer>();
171-
asset_server.watch_for_changes().unwrap();
172171
let shader = asset_server.load("shaders/instancing.wgsl");
173172

174173
let mesh_pipeline = world.resource::<MeshPipeline>();

examples/tools/scene_viewer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! With no arguments it will load the `FieldHelmet` glTF model from the repository assets subdirectory.
66
77
use bevy::{
8-
asset::{AssetServerSettings, LoadState},
8+
asset::LoadState,
99
gltf::Gltf,
1010
input::mouse::MouseMotion,
1111
math::Vec3A,

0 commit comments

Comments
 (0)