Query for unloaded assets #11997
-
In a big Bevy app, I'd like to globally check if anything is in the process of being loaded. My first attempt is this: fn is_all_done_loading(mut done: Local<bool>, query: Query<&LoadState>) {
if *done {
return;
};
let total = query.iter().count();
let ready = query
.iter()
.filter(|state| matches!(state, &&LoadState::Loaded))
.count();
info!("Load state: {ready}/{total}");
if total == ready && total > 0 {
*done = true;
}
} But it reports 0 total even though things are loading. I would like this to be non-intrusive if possible so I can avoid having a global untyped handle collection because I have many different plugins and many different asset types. Is there a way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I found a way that works and isn't too bad: #[derive(Debug, Resource)]
pub struct TrackingAssetServer {
pub server: AssetServer,
pub added: Vec<UntypedHandle>,
}
impl TrackingAssetServer {
/// Wraps the normal [`AssetServer`] call, tracking an untyped version of it such that we may later query
/// if all assets are loaded.
#[must_use = "not using the returned strong handle may result in the unexpected release of the asset"]
pub fn load<'a, A: Asset>(&mut self, path: impl Into<AssetPath<'a>>) -> Handle<A> {
let handle = self.server.load(path);
self.added.push(handle.clone_weak().untyped());
handle
}
} Then I just replaced all my uses of |
Beta Was this translation helpful? Give feedback.
-
Nice you could find a solution by yourself, but question: Would this query filter have helped you #5080 ? |
Beta Was this translation helpful? Give feedback.
I found a way that works and isn't too bad:
Then I just replaced all my uses of
…