Skip to content

Commit

Permalink
Log an error when registering an AssetSource after AssetPlugin has be…
Browse files Browse the repository at this point in the history
…en built (#10202)

# Objective

- Provides actionable feedback when users encounter the error in
#10162
- Complements #10186

## Solution

- Log an error when registering an AssetSource after the AssetPlugin has
been built (via DefaultPlugins). This will let users know that their
registration order needs changing

The outputted error message will look like this:
```rust
ERROR bevy_asset::server: 'AssetSourceId::Name(test)' must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)
```

---------

Co-authored-by: 66OJ66 <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent b1cc7ad commit 4e28fa2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use bevy_ecs::{
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, ScheduleLabel, SystemSet},
world::FromWorld,
};
use bevy_log::error;
use bevy_reflect::{FromReflect, GetTypeRegistration, Reflect, TypePath};
use std::{any::TypeId, sync::Arc};

Expand Down Expand Up @@ -349,6 +350,11 @@ impl AssetApp for App {
id: impl Into<AssetSourceId<'static>>,
source: AssetSourceBuilder,
) -> &mut Self {
let id = id.into();
if self.world.get_resource::<AssetServer>().is_some() {
error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id);
}

{
let mut sources = self
.world
Expand Down

0 comments on commit 4e28fa2

Please sign in to comment.