Skip to content

Commit

Permalink
Add reload_asset method to AssetServer. (bevyengine#5106)
Browse files Browse the repository at this point in the history
# Objective

Add support for custom `AssetIo` implementations to trigger reloading of an asset.

## Solution

- Add a public method to `AssetServer` to allow forcing the reloading of an asset.

---

## Changelog

- Add method `reload_asset` to `AssetServer`.


Co-authored-by: Robert G. Jakabosky <rjakabosky+neopallium@neoawareness.com>
  • Loading branch information
2 people authored and ItsDoot committed Feb 1, 2023
1 parent cfdd0e6 commit 3798746
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ impl AssetServer {
self.get_handle_untyped(handle_id)
}

/// Force an [`Asset`] to be reloaded.
///
/// This is useful for custom hot-reloading or for supporting `watch_for_changes`
/// in custom [`AssetIo`] implementations.
pub fn reload_asset<'a, P: Into<AssetPath<'a>>>(&self, path: P) {
self.load_untracked(path.into(), true);
}

pub(crate) fn load_untracked(&self, asset_path: AssetPath<'_>, force: bool) -> HandleId {
let server = self.clone();
let owned_path = asset_path.to_owned();
Expand Down

0 comments on commit 3798746

Please sign in to comment.