Skip to content

Query for unloaded assets #11997

Discussion options

You must be logged in to vote

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

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by torsteingrindvik
Comment options

You must be logged in to vote
4 replies
@torsteingrindvik
Comment options

@nicopap
Comment options

@torsteingrindvik
Comment options

@nicopap
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants