bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Warn that loading asset using a `PathBuf` does not handle labels

Open hukasu opened this issue 8 months ago • 4 comments

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

hukasu avatar May 16 '25 17:05 hukasu

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

hukasu avatar May 16 '25 17:05 hukasu

  • #13192
  • #11945

hukasu avatar May 16 '25 23:05 hukasu

I would prefer to fix this somehow, rather than simply warning.

alice-i-cecile avatar Jun 02 '25 18:06 alice-i-cecile

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
}

hukasu avatar Jun 02 '25 18:06 hukasu