ECS: Assets on web keep re-downloading (help: banging head against the wall) #13491
-
Bevy version0.13 The issueI have a chat room, and when a message comes in, there could be emojis that need to be downloaded for display. Those emojis need to be fully downloaded so that I can properly scale them! Here's my system that spawns the chats: pub fn spawn_chat_bubbles(
mut commands: Commands,
asset_server: Res<AssetServer>,
fonts: Res<Assets<VelloFont>>,
query_bubbles: Query<(Entity, &ChatBubble), Without<Children>>,
) {
for (entity, chat) in query_bubbles.iter() {
match chat {
ChatBubble::Chat { message, .. } => {
let handle = asset_server
.load::<VelloFont>("remote://fonts/Inconsolata_UltraExpanded-SemiBold.ttf");
info!("handle: {handle:?}");
let Some(font) = fonts.get(&handle) else {
warn!("asset does not exist");
continue;
};
... All I'm trying to do is assert that the asset needs to be fully loaded before we can spawn it in. The result? ![]() I cannot explain this. It re-downloads every update, instead of waiting for the existing handle to finish loading. Furthermore, it appears that the handle stays to be index 0 generation 0 until it finishes downloading, then it just gives me a new generation handle every update and refuses to give me the downloaded asset! Can anyone explain this? I saw @mockersf had a very similar discussion a while back, although it makes no sense 3 years later: #1863 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I believe the issue here is you're dropping the fn get_handle(asset_server: Res<AssetServer>, fonts: Res<Assets<VelloFont>>) {
// Handle created and loading started
let handle = asset_server.load::<VelloFont>("...");
let Some(font) = fonts.get(&handle) else {
// Highly likely the asset hasn't loaded immediately (latency, etc.)
// Because of that, this function always returns
warn!("asset does not exist");
return;
// Now that we've returned, the Handle is dropped, which causes the load to be cancelled
};
// ...
} Instead, try storing the |
Beta Was this translation helpful? Give feedback.
I believe the issue here is you're dropping the
Handle
on each frame;Instead, try storing the
Handle
in a resource (or anEntity
as aComponent
). That way theHa…