bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.34k stars 3.59k forks source link

Hot asset reloading example does not update when saving torus.gltf #14698

Open Anti-Alias opened 3 months ago

Anti-Alias commented 3 months ago

Bevy version

0.14.1

Relevant system information

Tested on:

What you did

Ran the hot_asset_reloading example on my Window 10 desktop, and Ubuntu laptop.

CLI args:

cargo run --example hot_asset_reloading --features file_watcher

What went wrong

Updating the torus gltf file does not update the model while running. Specifically, I updated the rotation quaternion in the file. Only restarting the app shows me the change.

Additional information

Editing the base color of the monkey model (same example) in version 0.11 seems to work, though if I add a rotation quaternion, the monkey's rotation only updates upon restarting the app.

On a personal project, I'm listening for image events AssetEvent<Image>:

pub fn read_image_events(
    mut events: EventReader<AssetEvent<Image>>,
) {
    for event in events.read() {
        println!("Got event: {event:?}");
    }
}

This system runs in the Update schedule. When starting up my game, my console logs the following:

Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 3, generation: 0} }
Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 5, generation: 0} }
Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 4, generation: 0} }

After updating / saving an image file image a couple of times, the console log looks like this:

Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 3, generation: 0} }  // Old
Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 5, generation: 0} }  // Old
Got event: Added { id: AssetId<bevy_render::texture::image::Image>{ index: 4, generation: 0} }  // Old
2024-08-10T20:33:26.687117Z  INFO bevy_asset::server: Reloading maps\tilesets\spring_forest.png because it has changed // New
2024-08-10T20:33:26.769548Z  INFO bevy_asset::server: Reloading maps\tilesets\spring_forest.png because it has changed // New
2024-08-10T20:33:39.859572Z  INFO bevy_asset::server: Reloading maps\tilesets\spring_forest.png because it has changed // New
2024-08-10T20:33:39.951233Z  INFO bevy_asset::server: Reloading maps\tilesets\spring_forest.png because it has changed // New

The four new lines at the end are bevy's internal logging. Clearly, bevy is detecting the change, but for some reason, it does not fire AssetEvent::<Image>::Modified events.

The PBR models that I'm spawning do not seem to update either. They do update if I restart the app, or do something that causes them to reload manually.

Pnoenix commented 3 months ago

I too tried to run "hot_asset_reloading" (cargo run --example hot_asset_reloading --features file_watcher). I ran it on the main branch version of bevy, and 0.14.1. Neither of them worked when changing the scale and rotation, although both versions detect a change of the torus.gltf file, and prints to the console (... INFO bevy_asset::server: Reloading models\torus\torus.gltf because it has changed)

Maybe rotation and scale on gltf is only updated on app restart, and if so, I think there should be added some documentation, to inform people that some fields are not affected by hot reloading.

I'm on windows 10, I don't know if operating system has anything to do with this though.

Anti-Alias commented 3 months ago

I might make a small example reproducing the lack of AssetEvent::<T>::Modified being fired for a variety of assets.

Pnoenix commented 3 months ago

Today I tried changing the config loading plugin I made (Github Repo), so that it doesn't require a Default implementation, and ran into the same issue as described above.

Before the asset was loaded with asset_server.load(...), however I changed it to be instantiated through asset_server.add(...), and then loading the asset itself with ron::de::from_str(...).

When doing it like this, both AssetEvent::LoadedWithDependencies and AssetEvent::Added gets called, however, AssetEvent::Modified no longer gets called.

This is on bevy version 0.14.1. This means that it is not only and issue with the GLTF asset/assetloader, and at least also a problem with certain custom asset loader implementations.

janhohenheim commented 3 months ago

@kaosat-dev this might be relevant for Blenvy

kaosat-dev commented 3 months ago

I can confirm this issue being present in 0.14.1, although it worked correctly in the last Bevy rc as far as I can remember.

PPakalns commented 15 hours ago

AssetEvent::Modified event is not triggered by Embedded asset reloading too.

INFO bevy_asset::server: 1387: Reloading entities.json because it has changed INFO bevy_asset::server: 1387: Reloading entities.png because it has changed

But zero AssetEvents are generated and systems can not reload changed assets.