#asset_server.reload_asset() - Force the game to wait until LoadState = Loaded

5 messages · Page 1 of 1 (latest)

paper field
#

Hi,

reload_asset() is async and I don't want to add another system just to update a certain texture when I click a button. How can I make the whole game wait until the texture is successfully reloaded so I can update the material afterwards? Right now, I have to click my button twice, to update the texture.

Hot Reloading doesn't work with textures, which is why I'm doing it manually. https://github.com/bevyengine/bevy/issues/8341

asset_server.reload_asset("img/output.png");
// TODO: Wait until asset_server.get_load_state("img/output.png") == bevy::asset::LoadState::Loaded
let updated_texture = asset_server.get_handle("img/output.png");
quick valley
#

Are you trying to update textures during development?

#

Or is this a feature that gets into release?

#

If it's not a feature that will be in a released game before next release, I think you could just work around it by checking for AssetEvents, if that file was changed you need to make any asset that uses the texture get considered "modified"

I do something like that when I change the filtering and color profile of images:

    if changed_textures {
      mats.iter_mut().last();
    }

I think that bug should be fixed once the Bevy Assets v2 PR is merged (hopefully in 0.12)

If it is something you need to perform well on the current release, you'd probably want to keep track of whatever assets need to get reloaded once an AssetEvent for that texture gets triggered

paper field