Asset Server silently fails when loading the wrong type
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
When loading an asset, the `AssetServer` will infer the type of the returned `Handle`. This leads to issues like the following code:
let mesh = asset_server.load(GltfAssetLabel::Mesh(0).from_asset("my_asset.gltf"));
commands.spawn((
Mesh3d(mesh),
MeshMaterial3d(materials.add(Color::BLACK)),
));
This will **silently fail** to render without any warnings or errors. The Rust analyzer won’t catch the issue either.
The root cause of the problem is subtle: `GltfAssetLabel::Mesh` does not return a `Handle` as expected, but instead returns a `Handle`. This mismatch leads to the asset **not rendering**, but Bevy doesn’t give any feedback, which is confusing, especially considering how Rust emphasizes **type safety** and catching these errors at compile time.
## What solution would you like?
Ideally, the Rust compiler should prevent this mismatch at compile time. If that’s not possible, I would like one of the systems involved here to **panic** or, at the very least, throw a **warning** to alert the developer to the issue.
## What alternative(s) have you considered?
Improved documentation could help clarify this distinction, but it doesn't fully address the **silent failure** of the asset not rendering due to the type mismatch.
Contributor guide
Assessment
This issue has not been assessed yet.