bevy
bevy copied to clipboard
Warn that loading asset using a `PathBuf` does not handle labels
What problem does this solve or what need does it fill?
Currently trying to load an asset passing a PathBuf with a label tries to load an asset with the label as part of the extension.
What solution would you like?
Add a warning that PathBuf does not support loading labeled assets
Additional context
doing asset_server.load(PathBuf::from("a.test#Test")) gives a Path not found error because the path that the AssetReader receives is a.test#Test instead of a.test
let string_slice: Handle<Test> = asset_server.load("a.test");
let string: Handle<Test> = asset_server.load("a.test".to_owned());
let path: Handle<Test> = asset_server.load(PathBuf::from("a.test"));
assert_eq!(string_slice, string);
assert_eq!(string_slice, path);
// Testing with labels
let string_slice: Handle<Test> = asset_server.load("a.test#Test");
let string: Handle<Test> = asset_server.load("a.test#Test".to_owned());
let path: Handle<Test> = asset_server.load(PathBuf::from("a.test#Test"));
assert_eq!(string_slice, string);
assert_eq!(string_slice, path); // Path not found
- #13192
- #11945
I would prefer to fix this somehow, rather than simply warning.
if i were to tackle this issue i would have a new type on this lines
// This name is already used inside bevy, so this would need to be named something else
struct AssetPath {
source: AssetSourceId,
file: String,
label: Option<String>
}
impl AssetPath {
fn new(file: String) -> Self {
Self {
source: AssetSourceId::Default,
file,
label: None
}
}
// with_label / with_source
}