Fallback asset paths
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Currently it is somewhat difficult switch between asset sources when one source does not have the asset available. Especially if it's being loaded from a server.
```rust
fn load_asset_from_folder_with_fallback(asset_server: Res) {
let id = if fs::exists("./assets/required.png") {
asset_server.load("required.png")
} else {
// This will always exist, but we still want users to be able to overwrite it for whatever reason.
asset_server.load("embedded://required.png");
};
// Do stuff
}
fn load_from_server_with_fallback(mut commands: Commands, asset_server: Res) {
let id = asset_server.load("https://www.server.com/required.png");
// I don't believe there is a way to check if the loading has failed.
}
```
## What solution would you like?
Some way of specifying a fall-back asset paths
```rust
fn load_asset(asset_server: Res) {
let id = asset_server.entry("embedded://required.png")
.with_fallback("required.png")
.handle();
let server_id = asset_server.entry("https://www.server.com/required.png")
.with_fallback("required.png")
.handle();
}
```
> Using entry here since the closest thing I could think of was `Hashmap::entry` bikeshedding appreciated.
## What alternative(s) have you considered?
Continue as is. This likely will only affect a very small amount of people.
Contributor guide
Research direction
Start by reading the AssetServer loading entry points shown in the issue, including load and the proposed entry API. Compare local, embedded, and server asset loading behavior, including how loading failure is reported. Done means users can specify fallback asset paths and obtain a handle that resolves to the fallback when the primary asset is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100