Skip to content

Commit b17cacb

Browse files
authored
Log reloads only when an asset has been reloaded (#21218)
# Objective - Prevent logging reloading for all the files that change in the assets folder to avoid logging for temporary files that are usually created during save or for raw asset files that are never really loaded because they are exported in another format. For example the asset folder could have .blender files but the user is exporting to glb/gltf. ## Solution - Added a new function called reload_internal that has a log parameter and moved the logging inside that function. ## Testing - Did you test these changes? If so, how? cargo run --example hot_asset_reloading --features bevy/file_watcher cp assets/models/animated/MorphStressTest.gltf assets/models/torus/torus.gltf - Are there any parts that need more testing? No - How can other people (reviewers) test your changes? Is there anything specific they need to know? This can be tested easily by running an example that loads an asset and do changes to it. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? Linux
1 parent 5aa5e52 commit b17cacb

File tree

1 file changed

+14
-7
lines changed
  • crates/bevy_asset/src/server

1 file changed

+14
-7
lines changed

crates/bevy_asset/src/server/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ impl AssetServer {
825825

826826
/// Kicks off a reload of the asset stored at the given path. This will only reload the asset if it currently loaded.
827827
pub fn reload<'a>(&self, path: impl Into<AssetPath<'a>>) {
828+
self.reload_internal(path, false);
829+
}
830+
831+
fn reload_internal<'a>(&self, path: impl Into<AssetPath<'a>>, log: bool) {
828832
let server = self.clone();
829833
let path = path.into().into_owned();
830834
IoTaskPool::get()
@@ -846,11 +850,15 @@ impl AssetServer {
846850
}
847851
}
848852

849-
if !reloaded
850-
&& server.data.infos.read().should_reload(&path)
851-
&& let Err(err) = server.load_internal(None, path, true, None).await
852-
{
853-
error!("{}", err);
853+
if !reloaded && server.data.infos.read().should_reload(&path) {
854+
match server.load_internal(None, path.clone(), true, None).await {
855+
Ok(_) => reloaded = true,
856+
Err(err) => error!("{}", err),
857+
}
858+
}
859+
860+
if log && reloaded {
861+
info!("Reloaded {}", path);
854862
}
855863
})
856864
.detach();
@@ -1769,8 +1777,7 @@ pub fn handle_internal_asset_events(world: &mut World) {
17691777
drop(infos);
17701778

17711779
for path in paths_to_reload {
1772-
info!("Reloading {path} because it has changed");
1773-
server.reload(path);
1780+
server.reload_internal(path, true);
17741781
}
17751782

17761783
#[cfg(not(any(target_arch = "wasm32", not(feature = "multi_threaded"))))]

0 commit comments

Comments
 (0)