diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index 60fb7f5cbb5bf1..0d8f1fe9512c7b 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -624,14 +624,7 @@ mod test { handle_to_path: Default::default(), asset_lifecycles: Default::default(), task_pool: Default::default(), - asset_io: Box::new(FileAssetIo::new( - asset_path, - #[cfg(all( - feature = "filesystem_watcher", - all(not(target_arch = "wasm32"), not(target_os = "android")) - ))] - false, - )), + asset_io: Box::new(FileAssetIo::new(asset_path, false)), }), } } diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index fb06b538c5a67b..22bf33ef80fb64 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -27,17 +27,23 @@ pub struct FileAssetIo { } impl FileAssetIo { - pub fn new>( - path: P, - #[cfg(feature = "filesystem_watcher")] watch_for_changes: bool, - ) -> Self { + pub fn new>(path: P, watch_for_changes: bool) -> Self { let file_asset_io = FileAssetIo { #[cfg(feature = "filesystem_watcher")] filesystem_watcher: Default::default(), root_path: Self::get_root_path().join(path.as_ref()), }; - #[cfg(feature = "filesystem_watcher")] if watch_for_changes { + #[cfg(any( + not(feature = "filesystem_watcher"), + target_arch = "wasm32", + target_os = "android" + ))] + panic!( + "Watch for changes requires the filesystem_watcher feature and cannot be used on \ + wasm32 / android targets" + ); + #[cfg(feature = "filesystem_watcher")] file_asset_io.watch_for_changes().unwrap(); } file_asset_io diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 1446fd9b99a0ab..b62d7537f2c7f7 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -44,10 +44,8 @@ pub struct AssetPlugin; pub struct AssetServerSettings { pub asset_folder: String, - #[cfg(all( - feature = "filesystem_watcher", - all(not(target_arch = "wasm32"), not(target_os = "android")) - ))] + /// Whether to watch for changes in asset files. Requires the `filesystem_watcher` feature, + /// and cannot be supported on the wasm32 arch nor android os. pub watch_for_changes: bool, } @@ -55,10 +53,6 @@ impl Default for AssetServerSettings { fn default() -> Self { Self { asset_folder: "assets".to_string(), - #[cfg(all( - feature = "filesystem_watcher", - all(not(target_arch = "wasm32"), not(target_os = "android")) - ))] watch_for_changes: false, } } @@ -74,11 +68,7 @@ pub fn create_platform_default_asset_io(app: &mut App) -> Box { .get_resource_or_insert_with(AssetServerSettings::default); #[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))] - let source = FileAssetIo::new( - &settings.asset_folder, - #[cfg(feature = "filesystem_watcher")] - settings.watch_for_changes, - ); + let source = FileAssetIo::new(&settings.asset_folder, settings.watch_for_changes); #[cfg(target_arch = "wasm32")] let source = WasmAssetIo::new(&settings.asset_folder); #[cfg(target_os = "android")]