From 4e28fa255d3e778f1f95f8ab19e9d5245bf1e3ce Mon Sep 17 00:00:00 2001 From: 66OJ66 <59021291+66OJ66@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:42:47 +0000 Subject: [PATCH] Log an error when registering an AssetSource after AssetPlugin has been built (#10202) # Objective - Provides actionable feedback when users encounter the error in https://github.com/bevyengine/bevy/issues/10162 - Complements https://github.com/bevyengine/bevy/pull/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 Co-authored-by: Alice Cecile --- crates/bevy_asset/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 66af7f0216..291e18b43b 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -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}; @@ -349,6 +350,11 @@ impl AssetApp for App { id: impl Into>, source: AssetSourceBuilder, ) -> &mut Self { + let id = id.into(); + if self.world.get_resource::().is_some() { + error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id); + } + { let mut sources = self .world