Skip to content

Dynamically changing the material of an entity #16787

Discussion options

You must be logged in to vote

I understood why there's this behavior, because Assets.get_strong_handle upgrades the ID (and in my case changes the UUID) to another one, consequently, the indexing in Bevy is no longer correct.

However, I don't see how to use Assets.get to insert it into the entity, because the get method returns Option<&A>, which is a reference.

let new_material_asset: &StandardMaterial = material_assets.get(asset_id).unwrap();
commands.entity(entity).insert(new_material_asset);

Solution

Actually, I understood that I can use the ID directly instead of retrieving the assets, and everything works perfectly ✅

let handle_material_asset_id = Handle::Weak(asset_id);
commands.entity(entity).insert(handle_mate…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vincent-herlemont
Comment options

Answer selected by vincent-herlemont
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant