Bevy version and features
0.16
What you did
1: load an asset
2: create a new strong handle
3: drop the original handle
4: query the load state
What went wrong
if we create the new handle via assets.get_strong_handle(original.id()) then the load state is NotLoaded.
if we create the new handle via original.clone() then the load state is Loaded.
Additional information
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, mess_with_handles)
.run();
}
fn mess_with_handles(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut images: ResMut<Assets<Image>>,
mut state: Local<usize>,
mut store1: Local<Option<Handle<Image>>>,
mut store2: Local<Option<Handle<Image>>>,
) {
match *state {
0 => {
let new_image = asset_server.load("whatever.png");
*store1 = Some(new_image);
*state = 1;
}
1 => {
if asset_server.is_loaded(store1.as_ref().unwrap().id()) {
*state = 2;
// this results in `NotLoaded`
*store2 = Some(images.get_strong_handle(store1.as_ref().unwrap().id()).unwrap());
// this would result in `Loaded`
// *store2 = Some(store1.as_ref().unwrap().clone());
}
}
2 => {
*store1 = Some(store1.as_ref().unwrap().clone_weak());
*state = 3;
}
_ => {
*state = 4;
commands.send_event(AppExit::default());
}
}
let id = store1.as_ref().unwrap().id();
println!(
"[{}]: load state: {:?}, available: {:?}",
*state,
asset_server.load_state(id),
images.get(id).is_some()
);
}
Bevy version and features
0.16
What you did
1: load an asset
2: create a new strong handle
3: drop the original handle
4: query the load state
What went wrong
if we create the new handle via
assets.get_strong_handle(original.id())then the load state isNotLoaded.if we create the new handle via
original.clone()then the load state isLoaded.Additional information