Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reloading doesn't trigger on files read via read_asset_bytes #6780

Closed
SpecificProtagonist opened this issue Nov 28, 2022 · 0 comments
Closed
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior

Comments

@SpecificProtagonist
Copy link
Contributor

Bevy version

0.9

What you did

Tried to write an asset loader that combines multiple files and enable hot reloading:

use bevy::{
    asset::{AssetLoader, LoadedAsset},
    prelude::*,
    reflect::TypeUuid,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(AssetPlugin {
            watch_for_changes: true,
            ..default()
        }))
        .add_asset_loader(TestAssetLoader)
        .add_asset::<TestAsset>()
        .add_startup_system(load)
        .run();
}

fn load(asset_server: Res<AssetServer>) {
    Box::leak(asset_server.load_untyped("test.main").into());
}

#[derive(TypeUuid)]
#[uuid = "2919310c-fbef-4d84-8f68-1bfb8d8b3ca0"]
struct TestAsset;

struct TestAssetLoader;

impl AssetLoader for TestAssetLoader {
    fn load<'a>(
        &'a self,
        _: &'a [u8],
        load_context: &'a mut bevy::asset::LoadContext,
    ) -> bevy::utils::BoxedFuture<'a, Result<(), bevy::asset::Error>> {
        info!("Loading");
        load_context.set_default_asset(LoadedAsset::new(TestAsset));
        Box::pin(async move {
            load_context.read_asset_bytes("secondary").await?;
            Ok(())
        })
    }

    fn extensions(&self) -> &[&str] {
        &["main"]
    }
}

What went wrong

If test.main gets touched, the asset gets reloaded, but if secondary gets touched, it doesn't.

@SpecificProtagonist SpecificProtagonist added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 28, 2022
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds and removed S-Needs-Triage This issue needs to be labelled labels Nov 28, 2022
@bors bors bot closed this as completed in 91ff782 Mar 2, 2023
Shfty pushed a commit to shfty-rust/bevy that referenced this issue Mar 19, 2023
# Objective

Fixes bevyengine#6780

## Solution

- record the asset path of each watched file
- call `AssetIo::watch_for_changes` in `LoadContext::read_asset_bytes`

---

## Changelog

### Fixed
- fixed hot reloading for `LoadContext::read_asset_bytes`

### Changed
- `AssetIo::watch_path_for_changes` allows watched path and path to reload to differ

## Migration Guide
- for custom `AssetIo`s, differentiate paths to watch and asset paths to reload as a consequence

Co-authored-by: Vincent Junge <specificprotagonist@posteo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants