From 9effc3e9b3d2fbeaf52d3a57a79ef9208fe95475 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Mon, 13 Sep 2021 14:02:28 +0000 Subject: [PATCH] Replace `.insert_resource(T::default())` calls with `init_resource::()` (#2807) # Objective I added the [INSERT_RESOURCE_WITH_DEFAULT](https://minersebas.github.io/bevy_lint/bevy_lint/static.INSERT_RESOURCE_WITH_DEFAULT.html) Lint to [bevy_lint](https://github.com/MinerSebas/bevy_lint) and while Testing it on bevy itself, I found several places where the Lint correctly triggered. ## Solution Replace `.insert_resource(T::default())` calls with `init_resource::()` --- crates/bevy_app/src/app.rs | 2 +- crates/bevy_text/src/lib.rs | 2 +- examples/3d/update_gltf_scene.rs | 2 +- examples/ecs/timers.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 4b9a71812f..a8180ff167 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -334,7 +334,7 @@ impl App { where T: Component, { - self.insert_resource(Events::::default()) + self.init_resource::>() .add_system_to_stage(CoreStage::First, Events::::update_system) } diff --git a/crates/bevy_text/src/lib.rs b/crates/bevy_text/src/lib.rs index ce91d4a2e8..ab87b21889 100644 --- a/crates/bevy_text/src/lib.rs +++ b/crates/bevy_text/src/lib.rs @@ -42,7 +42,7 @@ impl Plugin for TextPlugin { app.add_asset::() .add_asset::() .init_asset_loader::() - .insert_resource(DefaultTextPipeline::default()) + .init_resource::() .add_system_to_stage(CoreStage::PostUpdate, text2d_system) .add_system_to_stage(RenderStage::Draw, text2d::draw_text2d_system); } diff --git a/examples/3d/update_gltf_scene.rs b/examples/3d/update_gltf_scene.rs index 15a84a4919..6df061feb6 100644 --- a/examples/3d/update_gltf_scene.rs +++ b/examples/3d/update_gltf_scene.rs @@ -4,7 +4,7 @@ fn main() { App::new() .insert_resource(Msaa { samples: 4 }) .add_plugins(DefaultPlugins) - .insert_resource(SceneInstance::default()) + .init_resource::() .add_startup_system(setup) .add_system(scene_update) .add_system(move_scene_entities) diff --git a/examples/ecs/timers.rs b/examples/ecs/timers.rs index 12f3bfb1f1..d8e6c39c2d 100644 --- a/examples/ecs/timers.rs +++ b/examples/ecs/timers.rs @@ -3,7 +3,7 @@ use bevy::{log::info, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(Countdown::default()) + .init_resource::() .add_startup_system(setup_system) .add_system(countdown_system) .add_system(timer_system)