mirror of
https://github.com/bevyengine/bevy
synced 2024-09-20 06:22:01 +00:00
Remove AssetServer::watch_for_changes()
(#5968)
# Objective `AssetServer::watch_for_changes()` is racy and redundant with `AssetServerSettings`. Closes #5964. ## Changelog * Remove `AssetServer::watch_for_changes()` * Add `AssetServerSettings` to the prelude. * Minor cleanup. ## Migration Guide `AssetServer::watch_for_changes()` was removed. Instead, use the `AssetServerSettings` resource. ```rust app // AssetServerSettings must be inserted before adding the AssetPlugin or DefaultPlugins. .insert_resource(AssetServerSettings { watch_for_changes: true, ..default() }) ``` Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
91a235e6d6
commit
28205fd3f4
6 changed files with 27 additions and 25 deletions
|
@ -79,7 +79,16 @@ pub struct AssetServerInternal {
|
|||
///
|
||||
/// The asset server is the primary way of loading assets in bevy. It keeps track of the load state
|
||||
/// of the assets it manages and can even reload them from the filesystem with
|
||||
/// [`AssetServer::watch_for_changes`]!
|
||||
/// ```
|
||||
/// # use bevy_asset::*;
|
||||
/// # use bevy_app::*;
|
||||
/// # let mut app = App::new();
|
||||
/// // AssetServerSettings must be inserted before adding the AssetPlugin or DefaultPlugins.
|
||||
/// app.insert_resource(AssetServerSettings {
|
||||
/// watch_for_changes: true,
|
||||
/// ..Default::default()
|
||||
/// });
|
||||
/// ```
|
||||
///
|
||||
/// The asset server is a _resource_, so in order to access it in a system you need a `Res`
|
||||
/// accessor, like this:
|
||||
|
@ -169,13 +178,6 @@ impl AssetServer {
|
|||
loaders.push(Arc::new(loader));
|
||||
}
|
||||
|
||||
/// Enable watching of the filesystem for changes, if support is available, starting from after
|
||||
/// the point of calling this function.
|
||||
pub fn watch_for_changes(&self) -> Result<(), AssetServerError> {
|
||||
self.asset_io().watch_for_changes()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets a strong handle for an asset with the provided id.
|
||||
pub fn get_handle<T: Asset, I: Into<HandleId>>(&self, id: I) -> Handle<T> {
|
||||
let sender = self.server.asset_ref_counter.channel.sender.clone();
|
||||
|
|
|
@ -29,7 +29,9 @@ mod path;
|
|||
/// The `bevy_asset` prelude.
|
||||
pub mod prelude {
|
||||
#[doc(hidden)]
|
||||
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
|
||||
pub use crate::{
|
||||
AddAsset, AssetEvent, AssetServer, AssetServerSettings, Assets, Handle, HandleUntyped,
|
||||
};
|
||||
}
|
||||
|
||||
pub use anyhow::Error;
|
||||
|
|
|
@ -6,6 +6,13 @@ use bevy::{prelude::*, tasks::IoTaskPool, utils::Duration};
|
|||
|
||||
fn main() {
|
||||
App::new()
|
||||
// This tells the AssetServer to watch for changes to assets.
|
||||
// It enables our scenes to automatically reload in game when we modify their files.
|
||||
// AssetServerSettings must be inserted before the DefaultPlugins are added.
|
||||
.insert_resource(AssetServerSettings {
|
||||
watch_for_changes: true,
|
||||
..default()
|
||||
})
|
||||
.add_plugins(DefaultPlugins)
|
||||
.register_type::<ComponentA>()
|
||||
.register_type::<ComponentB>()
|
||||
|
@ -65,10 +72,6 @@ fn load_scene_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
scene: asset_server.load(SCENE_FILE_PATH),
|
||||
..default()
|
||||
});
|
||||
|
||||
// This tells the AssetServer to watch for changes to assets.
|
||||
// It enables our scenes to automatically reload in game when we modify their files
|
||||
asset_server.watch_for_changes().unwrap();
|
||||
}
|
||||
|
||||
// This system logs all ComponentA components in our world. Try making a change to a ComponentA in
|
||||
|
|
|
@ -8,7 +8,7 @@ use bevy::{
|
|||
prelude::*,
|
||||
reflect::TypeUuid,
|
||||
render::{
|
||||
camera::{Camera, RenderTarget},
|
||||
camera::RenderTarget,
|
||||
render_resource::{
|
||||
AsBindGroup, Extent3d, ShaderRef, TextureDescriptor, TextureDimension, TextureFormat,
|
||||
TextureUsages,
|
||||
|
@ -20,13 +20,12 @@ use bevy::{
|
|||
};
|
||||
|
||||
fn main() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(DefaultPlugins)
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(Material2dPlugin::<PostProcessingMaterial>::default())
|
||||
.add_startup_system(setup)
|
||||
.add_system(main_camera_cube_rotator_system);
|
||||
|
||||
app.run();
|
||||
.add_system(main_camera_cube_rotator_system)
|
||||
.run();
|
||||
}
|
||||
|
||||
/// Marks the first camera cube (rendered to a texture.)
|
||||
|
@ -40,11 +39,8 @@ fn setup(
|
|||
mut post_processing_materials: ResMut<Assets<PostProcessingMaterial>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
asset_server.watch_for_changes().unwrap();
|
||||
|
||||
let window = windows.get_primary_mut().unwrap();
|
||||
let window = windows.primary_mut();
|
||||
let size = Extent3d {
|
||||
width: window.physical_width(),
|
||||
height: window.physical_height(),
|
||||
|
|
|
@ -168,7 +168,6 @@ pub struct CustomPipeline {
|
|||
impl FromWorld for CustomPipeline {
|
||||
fn from_world(world: &mut World) -> Self {
|
||||
let asset_server = world.resource::<AssetServer>();
|
||||
asset_server.watch_for_changes().unwrap();
|
||||
let shader = asset_server.load("shaders/instancing.wgsl");
|
||||
|
||||
let mesh_pipeline = world.resource::<MeshPipeline>();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! With no arguments it will load the `FieldHelmet` glTF model from the repository assets subdirectory.
|
||||
|
||||
use bevy::{
|
||||
asset::{AssetServerSettings, LoadState},
|
||||
asset::LoadState,
|
||||
gltf::Gltf,
|
||||
input::mouse::MouseMotion,
|
||||
math::Vec3A,
|
||||
|
|
Loading…
Reference in a new issue