pub struct BevyCachePlugin {
pub config: CacheConfig,
}Expand description
Plugin that registers the file cache system.
Registers a "cache" asset source that maps to the OS cache directory.
Any Bevy asset type can be loaded from the cache using the cache:// scheme;
Bevy’s built-in loaders handle the file based on its real extension.
Must be added before DefaultPlugins so that the asset source is
available when AssetPlugin initialises.
The plugin automatically registers the cache directory with Bevy’s
AssetPlugin using platform_default, so if you enable file watching in
AssetPlugin the cache directory is watched alongside the normal assets
folder — no extra configuration required:
App::new()
.add_plugins(BevyCachePlugin::new("my_game"))
.add_plugins(DefaultPlugins.set(AssetPlugin {
watch_for_changes_override: Some(true),
..default()
}))
.run();Without a watch_for_changes_override the cache source is still registered
and accessible via cache://; watching is just disabled.
§Hot-reloading the manifest
Enable the hot_reload Cargo feature to additionally watch the
manifest.cache_manifest file itself and have CacheManifest re-synced
automatically when it changes on disk.
After adding the plugin, use CacheManifest to store and query cached
assets, and CacheQueue to enqueue asset handles for deferred caching:
fn cache_screenshot(mut cache: Cache) {
let png_data: Vec<u8> = render_my_screenshot();
cache.store("scene_01", "png", std::io::Cursor::new(png_data), None)
.expect("cache write failed");
}
fn cache_asset_by_handle(
mut pending: ResMut<CacheQueue>,
assets: Res<Assets<MyAsset>>,
handle: Res<MyAssetHandle>,
) {
if let Some(asset) = assets.get(&handle.0) {
// Reflect-based: serialized to RON via ReflectSerializer
pending.enqueue_reflect(
Box::new(asset.clone()),
"my_asset_key",
"ron",
None,
);
}
}
fn load_cached(mut cache: Cache, asset_server: Res<AssetServer>) {
if let Some(path) = cache.asset_path("scene_01") {
// Bevy detects ".png" and uses ImageLoader automatically.
let handle: Handle<Image> = asset_server.load(path);
}
}Fields§
§config: CacheConfigImplementations§
Trait Implementations§
Source§impl Default for BevyCachePlugin
impl Default for BevyCachePlugin
Source§fn default() -> BevyCachePlugin
fn default() -> BevyCachePlugin
Source§impl Plugin for BevyCachePlugin
impl Plugin for BevyCachePlugin
Source§fn ready(&self, _app: &App) -> bool
fn ready(&self, _app: &App) -> bool
finish should be called.Source§fn finish(&self, _app: &mut App)
fn finish(&self, _app: &mut App)
App, once all plugins registered are ready. This can
be useful for plugins that depends on another plugin asynchronous setup, like the renderer.Source§fn cleanup(&self, _app: &mut App)
fn cleanup(&self, _app: &mut App)
Auto Trait Implementations§
impl Freeze for BevyCachePlugin
impl RefUnwindSafe for BevyCachePlugin
impl Send for BevyCachePlugin
impl Sync for BevyCachePlugin
impl Unpin for BevyCachePlugin
impl UnsafeUnpin for BevyCachePlugin
impl UnwindSafe for BevyCachePlugin
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more