Skip to content

Commit 16d710c

Browse files
authored
Fix asset loader registration warning (#11870)
# Objective When registering and preregistering asset loaders, there would be a `warn!` if multiple asset loaders use a given extension, and an `info!` if multiple asset loaders load the same asset type. Since both of these situations are individually fine, it was decided that these messages should be removed. ## Solution Replace both of these messages with a new `warn!` that notes that if multiple asset loaders share the same asset type _and_ share extensions, that the loader must be specified in the `.meta` file for those assets in order to solve the ambiguity. This is a more useful message, since it notes when a user must take special action / consideration.
1 parent ebaa347 commit 16d710c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crates/bevy_asset/src/server/loaders.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
path::AssetPath,
44
};
55
use async_broadcast::RecvError;
6-
use bevy_log::{error, info, warn};
6+
use bevy_log::{error, warn};
77
use bevy_tasks::IoTaskPool;
88
use bevy_utils::{HashMap, TypeIdMap};
99
use std::{any::TypeId, sync::Arc};
@@ -40,14 +40,15 @@ impl AssetLoaders {
4040
};
4141

4242
if is_new {
43+
let mut duplicate_extensions = Vec::new();
4344
for extension in loader.extensions() {
4445
let list = self
4546
.extension_to_loaders
4647
.entry(extension.to_string())
4748
.or_default();
4849

4950
if !list.is_empty() {
50-
warn!("duplicate registration for extension `{extension}`.");
51+
duplicate_extensions.push(extension);
5152
}
5253

5354
list.push(loader_index);
@@ -60,8 +61,10 @@ impl AssetLoaders {
6061
.entry(loader_asset_type)
6162
.or_default();
6263

63-
if !list.is_empty() {
64-
info!("duplicate registration for type `{loader_asset_type_name}`.");
64+
let duplicate_asset_registration = !list.is_empty();
65+
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
66+
warn!("Duplicate AssetLoader registered for Asset type `{loader_asset_type_name}` with extensions `{duplicate_extensions:?}`. \
67+
Loader must be specified in a .meta file in order to load assets of this type with these extensions.");
6568
}
6669

6770
list.push(loader_index);
@@ -98,14 +101,15 @@ impl AssetLoaders {
98101

99102
self.preregistered_loaders.insert(type_name, loader_index);
100103
self.type_name_to_loader.insert(type_name, loader_index);
104+
let mut duplicate_extensions = Vec::new();
101105
for extension in extensions {
102106
let list = self
103107
.extension_to_loaders
104108
.entry(extension.to_string())
105109
.or_default();
106110

107111
if !list.is_empty() {
108-
warn!("duplicate preregistration for extension `{extension}`.");
112+
duplicate_extensions.push(extension);
109113
}
110114

111115
list.push(loader_index);
@@ -116,8 +120,10 @@ impl AssetLoaders {
116120
.entry(loader_asset_type)
117121
.or_default();
118122

119-
if !list.is_empty() {
120-
info!("duplicate preregistration for type `{loader_asset_type_name}`.");
123+
let duplicate_asset_registration = !list.is_empty();
124+
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
125+
warn!("Duplicate AssetLoader preregistered for Asset type `{loader_asset_type_name}` with extensions `{duplicate_extensions:?}`. \
126+
Loader must be specified in a .meta file in order to load assets of this type with these extensions.");
121127
}
122128

123129
list.push(loader_index);

0 commit comments

Comments
 (0)