#How to get a SavedAsset<T> from Handle<T> and Assets<T>

5 messages · Page 1 of 1 (latest)

upbeat dew
#

Hi, I'm writing a custom saver now. I found the AssetSaver#save() needs a SavedAsset parameter. Can I get that from Assets and Handle, and how do I do that?

sand crag
#

oh nope it's a method, the other two are the only associated functions

sand crag
#

i'm a relative novice, but it looks like bevy_asset wants asset saving to fit after a load
might be assetserver's job

upbeat dew
#

Thanks. I found a way to do that.
Firstly, I removed the asset from the Assets<T>, and I got ownership of that asset. Then

fn foo(asset: TableAsset, ...) -> ...{
...
  let loaded: LoadedAsset<TableAsset> = asset.into();
  let erased = ErasedLoadedAsset::from(loaded);
  let saved = SavedAsset::from_loaded(&erased).ok_or(anyhow::anyhow!("Noooooo!!"))?;
...
}