Skip to content

No convenient way to set default assets through the AssetServer #12192

Open
@SludgePhD

Description

@SludgePhD

What problem does this solve or what need does it fill?

Currently, it seems like the simplest way to set the default value of an Assets collection is this:

fn load_default_font(mut fonts: ResMut<Assets<Font>>) {
    let bytes = include_bytes!("font.ttf");
    let font = Font::try_from_bytes(bytes.to_vec()).unwrap();

    fonts.insert(AssetId::<Font>::DEFAULT_UUID, font);
}

This sidesteps the whole asset system, and requires including potentially large data in the binary (in my case, a 14 MiB font file), so it's not ideal.

AssetServer has no methods that load an asset into an existing Handle/AssetId, so it cannot directly be used for this. It's possible to load the asset with a different Handle, listen to the asset event that indicates it has loaded, and then copy the asset over to the default ID. This is extremely inconvenient, though.

What solution would you like?

AssetServer should expose some way of asynchronously loading an asset into an existing Handle or AssetId, overwriting whatever is already there.

What alternative(s) have you considered?

None so far. Open to suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions