Skip to content

Assets path are already removed on AssetEvents::Unused #19946

@mirsella

Description

@mirsella

Bevy version

0.16.1

What you did

// in any Update schedule
pub fn log_asset_events<A: Asset>(
    mut asset_events: EventReader<AssetEvent<A>>,
    asset_server: Res<AssetServer>,
) {
    for event in asset_events.read() {
        if let AssetEvent::Added { id } = event {
            let path = asset_server.get_path(*id);
            trace!("Loading asset {id} at `{path:?}`");
        } else if let AssetEvent::Unused { id } = event {
            let path = asset_server.get_path(*id);
            debug!("Unused asset {id} at path `{path:?}`");
        }
    }
}

What went wrong

on ::Unused event, the AssetServer::get_path method returns None for asset id that had a path on ::Loading event

Additional information

i guess its because the assets information have already been removed, but maybe its possible to keep them a little while longer; just the path one more frame to allows systems to easily access the path for logging for example ?

i marked as bug because in a really naive approach, between Unused and Removed events the assets could still be here, but in practice when we read the event its already too late

the users can just store the path in a Local otherwise, but having get_path working would still be useful as a QoL improvement, so users dont have to find that it doesn't work, then wonder why and implement a solution themselves.

if this is not useful or worth it, feel free to close this !!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions