Description
Bevy version
0.16.0-dev (main)
What you did / What went wrong
Reloading a gltf file does not reload dependencies that are stored in separate files, such as image files.
The culprit is in bevy_glts/src/loader/mod.rs:L1739
, where the gltf loader calls the load
function on any image files that are stored as a path in the gltf file. Following the load function call down the call stack leads to the get_or_create_path_handle_internal
function on bevy_asset/src/server/info.rs/L200
. This function will only load an already loaded asset if the asset load mode is set to HandleLoadingMode::Force
. However, the load
function called from the gltf loader has no way to set the HandleLoadingMode
to anything other than Request
, which will not reload already loaded assets.
Furthermore, even when reloading an asset with HandleLoadingMode::Force
(as is done in the reload
function on the asset server), different loader settings will be ignored in favor of the original loader settings. The culprit is once again the get_or_create_path_handle_internal
on bevy_asset/src/server/info.rs/L200
. Loader settings are stored in the Handle
of an asset, and the get_or_create_path_handle_internal
function only stores loader settings for freshly loaded assets.
As there is no reload_with_settings
function, this is only relevant for #17875 which adds a way to change the gltf loader's default image sampler at runtime (although a reload_with_settings
function would be nice to have).
Solution
Unfortunately there is no obvious, easy solution to this issue. Even if we modified the load
function called from the gltf loader to be capable of using HandleLoadingMode::Force
, it wouldn't know when to use it as asset loaders are "reload unaware". Even if we added the required infrastructure to make asset loaders "reload aware", that would require every asset loader to deal with reload logic manually, logic which should be quite simple (if reloading, force load dependencies). We could add infrastructure to the asset server to track reloads, and use HandleLoadingMode::Force
for any dependencies of an asset that is reloading, but that would be a very involved change.
For the issue where asset reloads can't change loader settings: even though we could easily modify HandleLoadingMode::Force
to update the loader settings of an asset, is this desirable? Assets could change dramatically based on loader settings. You could make a reasonable argument that assets loaded with different loader settings should be considered different assets entirely.
I'm not sure what the best way to approach this is.