bevyengine / bevyengine/bevy

Custom AssetSource(s) must be registered before DefaultPlugins in order to work

Open
#10,162 5 comments 0 reactions 0 assignees View on GitHub
A-App A-Assets C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.12-dev

## What you did

I attempted to register an AssetSource:

```rust
fn main() {
App::new()
.add_plugins(
DefaultPlugins.set(AssetPlugin {
mode: AssetMode::ProcessedDev,
..default()
}),
)
.register_asset_source(
"test",
AssetSource::build()
.with_reader(|| Box::new(FileAssetReader::new("test")))
)
.run();
}
```

## What went wrong

When I tried to load a handle from that AssetSource, I got this error:
```rust
ERROR bevy_asset::server: Asset Source 'AssetSourceId::Name(test)' does not exist
```

## Additional information

Registering the asset source _before_ adding the `DefaultPlugins` resolved the issue - this seems a bit counter-intuitive though.

I think there's broadly 2 options to stop others encountering this issue:

1) Mention this ordering requirement in the `register_asset_source` comments:
https://github.com/bevyengine/bevy/blob/6b070b1776c63aa69cc60185e04c293b32e60164/crates/bevy_asset/src/lib.rs#L244-L245

2) Call `build_sources` from `Plugin::finish()` instead of `Plugin::build()`
https://github.com/bevyengine/bevy/blob/6b070b1776c63aa69cc60185e04c293b32e60164/crates/bevy_asset/src/lib.rs#L139-L140
This might not work for anyone attempting to load handles from a custom `AssetSource` in a `FromWorld` impl, although a similar issue was resolved in https://github.com/bevyengine/bevy/pull/9429

Contributor guide

Open the contributing guide

Research direction

Start in crates/bevy_asset/src/lib.rs, especially the register_asset_source comments and the build_sources call in Plugin::build(). Reproduce the reported ordering with DefaultPlugins and a custom FileAssetReader, then determine whether the ordering should be documented or the source-building lifecycle changed. Done means a custom AssetSource works as expected or the ordering requirement is clearly documented, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.