-
Hello Bevy Community, I'm encountering an issue with AssetServer::get_load_state in my Bevy project where I'm trying to check if a specific asset is loaded. However, I'm running into a type conversion error. Here’s the problematic part of my code: pub(crate) fn adjust_floor_transform(
mut commands: Commands,
mut transforms: Query<(Entity, &mut Transform, &Name)>,
asset_server: Res<AssetServer>,
) {
if asset_server.get_load_state("sponza/sponza.glb#Scene0") == Option::from(bevy::asset::LoadState::Loaded) {
for (entity, mut transform, name) in transforms.iter_mut() {
if name.as_str() == "SpecificFloorName" {
transform.translation.y += 1.0;
println!("Adjusted transform for {}", name.as_str());
}
}
}
}
The error message I receive is: error[E0277]: the trait bound `UntypedAssetId: From<&str>` is not satisfied
--> src/setup.rs:21:36
|
21 | if asset_server.get_load_state("sponza/sponza.glb#Scene0") == Option::from(bevy::asset::LoadState::Loaded) {
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&str>` is not implemented for `UntypedAssetId`, which is required by `&str: Into<UntypedAssetId>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
<UntypedAssetId as From<bevy::prelude::Handle<A>>>
<UntypedAssetId as From<UntypedHandle>>
<UntypedAssetId as From<AssetId<A>>>
<UntypedAssetId as From<&bevy::prelude::Handle<A>>>
<UntypedAssetId as From<&UntypedHandle>>
= note: required for `&str` to implement `Into<UntypedAssetId>`
note: required by a bound in `AssetServer::get_load_state`
--> /Users/xbz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_asset-0.13.2/src/server/mod.rs:756:43
|
756 | pub fn get_load_state(&self, id: impl Into<UntypedAssetId>) -> Option<LoadState> {
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `AssetServer::get_load_state`
I understand that the issue arises because &str cannot be converted directly to UntypedAssetId, which is expected by get_load_state. How can I correctly convert a string path to an UntypedAssetId or is there a easier way to do this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
pub(crate) fn adjust_floor_transform(
mut commands: Commands,
mut transforms: Query<(Entity, &mut Transform, &Name)>,
asset_server: Res<AssetServer>,
) {
let handle = asset_server.get_handle::<Scene>("sponza/sponza.glb#Scene0").expect("handle should be loading or loaded");
if matches!(asset_server.get_load_state(&handle), Some(LoadState::Loaded)) {
for (entity, mut transform, name) in transforms.iter_mut() {
if name.as_str() == "SpecificFloorName" {
transform.translation.y += 1.0;
println!("Adjusted transform for {}", name.as_str());
}
}
}
} |
Beta Was this translation helpful? Give feedback.
&str
doesn't implementInto<UntypedAssetId>
. You'll need to use a type that does (you can see some of the types that do in the error message), such asHandle<A>
. So you could probably use something like: