diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 3248606cc9d7b..0a4fe716fb61c 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -536,6 +536,14 @@ impl Assets { pub fn asset_events(mut assets: ResMut, mut events: EventWriter>) { events.send_batch(assets.queued_events.drain(..)); } + + /// A run condition for [`asset_events`]. The system will not run if there are no events to + /// flush. + /// + /// [`asset_events`]: Self::asset_events + pub(crate) fn asset_events_condition(assets: Res) -> bool { + !assets.queued_events.is_empty() + } } /// A mutable iterator over [`Assets`]. diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 4f0d259d45b0d..41d6ef834f0fc 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -386,7 +386,10 @@ impl AssetApp for App { .add_event::>() .register_type::>() .register_type::>() - .add_systems(AssetEvents, Assets::::asset_events) + .add_systems( + AssetEvents, + Assets::::asset_events.run_if(Assets::::asset_events_condition), + ) .add_systems(UpdateAssets, Assets::::track_assets.in_set(TrackAssets)) }