bevyengine / bevyengine/bevy

Gltf assets do not reload correctly

Open
#18,267 2 comments 0 reactions 0 assignees View on GitHub
A-Assets A-glTF C-Bug S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

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.

Contributor guide

Open the contributing guide

Research direction

Start by reading bevy_gltf/src/loader/mod.rs around L1739 and bevy_asset/src/server/info.rs around L200, then trace the asset server reload path and HandleLoadingMode handling. Compare dependency reload behavior with loader-settings reuse, and define tests that demonstrate the intended behavior before choosing an approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.