Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl From<&AssetPath> for HandleId #9132

Merged

Conversation

tguichaoua
Copy link
Contributor

@tguichaoua tguichaoua commented Jul 12, 2023

Objective

In AssetLoader::load(), I have an AssetPath to a dependency asset.
I get a handle to this dependency asset using LoadContext::get_handle() passing the AssetPath. But I also need to pass this AssetPath to LoadedAsset::with_dependency() later.

The current solution for this problem is either use clone(), but AssetPath may contains owned data.

let dependency_path: AssetPath = _;
let dependency = load_context.get_handle(dependency_path.clone());
// ...
load_context.set_default_asset(LoadedAsset::new(my_asset).with_dependency(dependency_path));

Or to use AssetPathId::from(&path) which is a bit verbose.

let dependency_path: AssetPath = _;
let dependency = load_context.get_handle(AssetPathId::from(&dependency_path));
// ...
load_context.set_default_asset(LoadedAsset::new(my_asset).with_dependency(dependency_path));

Ideal solution (introduced by this PR) is to pass a reference to get_handle().

let dependency_path: AssetPath = _;
let dependency = load_context.get_handle(&dependency_path);
// ...
load_context.set_default_asset(LoadedAsset::new(my_asset).with_dependency(dependency_path));

Solution

Implement From<&AssetPath> for HandleId


Changelog

  • Added: HandleId can be build from a reference to AssetPath.

@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Jul 12, 2023
@james7132 james7132 added this pull request to the merge queue Jul 15, 2023
Merged via the queue into bevyengine:main with commit a30da00 Jul 15, 2023
@tguichaoua tguichaoua deleted the util/handle_id_from_asset_path_ref branch July 16, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants