Skip to content

Commit 51edf9c

Browse files
authored
Remove the UpdateAssets and AssetEvents schedules (#11986)
# Objective Fix #11845. ## Solution Remove the `UpdateAssets` and `AssetEvents` schedules. Moved the `UpdateAssets` systems to `PreUpdate`, and `AssetEvents` systems into `First`. The former is meant to run before any of the event flushes. ## Future Work It'd be ideal if we could manually flush the events for assets to avoid needing two, sort of redundant, systems. This should at least let them potentially run in parallel with all of the systems in the schedules they were moved to. --- ## Changelog Removed: `UpdateAssets` schedule from the main schedule. All systems have been moved to `PreUpdate`. Removed: `AssetEvents` schedule from the main schedule. All systems have been move to `First` with the same system sets. ## Migration Guide TODO
1 parent 5d941d5 commit 51edf9c

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

crates/bevy_asset/src/lib.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ use crate::{
4646
io::{embedded::EmbeddedAssetRegistry, AssetSourceBuilder, AssetSourceBuilders, AssetSourceId},
4747
processor::{AssetProcessor, Process},
4848
};
49-
use bevy_app::{App, First, MainScheduleOrder, Plugin, PostUpdate};
49+
use bevy_app::{App, First, Plugin, PreUpdate};
5050
use bevy_ecs::{
5151
reflect::AppTypeRegistry,
52-
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, ScheduleLabel, SystemSet},
52+
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, SystemSet},
5353
system::Resource,
5454
world::FromWorld,
5555
};
@@ -146,7 +146,6 @@ impl AssetPlugin {
146146

147147
impl Plugin for AssetPlugin {
148148
fn build(&self, app: &mut App) {
149-
app.init_schedule(UpdateAssets).init_schedule(AssetEvents);
150149
let embedded = EmbeddedAssetRegistry::default();
151150
{
152151
let mut sources = app
@@ -218,16 +217,9 @@ impl Plugin for AssetPlugin {
218217
.init_asset::<LoadedUntypedAsset>()
219218
.init_asset::<()>()
220219
.add_event::<UntypedAssetLoadFailedEvent>()
221-
.configure_sets(
222-
UpdateAssets,
223-
TrackAssets.after(handle_internal_asset_events),
224-
)
225-
.add_systems(UpdateAssets, handle_internal_asset_events)
220+
.configure_sets(PreUpdate, TrackAssets.after(handle_internal_asset_events))
221+
.add_systems(PreUpdate, handle_internal_asset_events)
226222
.register_type::<AssetPath>();
227-
228-
let mut order = app.world.resource_mut::<MainScheduleOrder>();
229-
order.insert_after(First, UpdateAssets);
230-
order.insert_after(PostUpdate, AssetEvents);
231223
}
232224
}
233225

@@ -387,10 +379,13 @@ impl AssetApp for App {
387379
.register_type::<Handle<A>>()
388380
.register_type::<AssetId<A>>()
389381
.add_systems(
390-
AssetEvents,
391-
Assets::<A>::asset_events.run_if(Assets::<A>::asset_events_condition),
382+
First,
383+
Assets::<A>::asset_events
384+
.before(bevy_ecs::event::event_update_system::<AssetEvent<A>>)
385+
.run_if(Assets::<A>::asset_events_condition)
386+
.in_set(AssetEvents),
392387
)
393-
.add_systems(UpdateAssets, Assets::<A>::track_assets.in_set(TrackAssets))
388+
.add_systems(PreUpdate, Assets::<A>::track_assets.in_set(TrackAssets))
394389
}
395390

396391
fn register_asset_reflect<A>(&mut self) -> &mut Self
@@ -422,14 +417,10 @@ impl AssetApp for App {
422417
#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone)]
423418
pub struct TrackAssets;
424419

425-
/// Schedule where [`Assets`] resources are updated.
426-
#[derive(Debug, Hash, PartialEq, Eq, Clone, ScheduleLabel)]
427-
pub struct UpdateAssets;
428-
429-
/// Schedule where events accumulated in [`Assets`] are applied to the [`AssetEvent`] [`Events`] resource.
420+
/// A system set where events accumulated in [`Assets`] are applied to the [`AssetEvent`] [`Events`] resource.
430421
///
431422
/// [`Events`]: bevy_ecs::event::Events
432-
#[derive(Debug, Hash, PartialEq, Eq, Clone, ScheduleLabel)]
423+
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
433424
pub struct AssetEvents;
434425

435426
#[cfg(test)]

0 commit comments

Comments
 (0)