NiklasEi / bevy_asset_loader

Bevy plugin helping with asset loading and organization
Apache License 2.0
459 stars 52 forks source link

Add a failure state alongside the success state? #79

Closed ruifengx closed 1 year ago

ruifengx commented 1 year ago

It seems this crate only keeps track of Loaded assets, and waits indefinitely if some of the assets actually Failed loading. (I drew this conclusion based on the following code. Please correct me if I am wrong.) I don't believe the loading logic could recover after get_load_state returns Failed, so it seems that there is no point waiting any longer.

https://github.com/NiklasEi/bevy_asset_loader/blob/79d604dde42ccb36f7573bbc95bf22feb9836bc3/bevy_asset_loader/src/loading_state/systems.rs#L77-L83

Rather than waiting for the impossible, it would be great if this crate could also collect all the failures (ideally as asset paths) and transition to a "load failure" state, so the game could do graceful error reporting in this case. I believe there is already enough information for this kind of error reporting via the current AssetCollection interface.

I imagine in the new approach, Loaded and Failed both count as done in terms of progress tracking (perhaps also assert against NotLoaded and Unloaded, because it should be impossible to have such values returned from get_load_state in the loading stage), collect all the asset paths for Failed assets, and after done >= total, transition to either the "success" or the "failure" state according to the number of Failed assets. IMO tracking the Failed assets should not introduce too much overhead, so it could be the default behaviour (or of course, it could also be behind a feature gate). An alternative approach would be to unconditionally transition to the only "next" state, and let the systems there check the loading status manually by e.g. querying the existence of the AssetLoadingFailure resource.

NiklasEi commented 1 year ago

That's a nice idea. I think I prefer the failing state over some resource that needs to be actively queried.