From 00323b3048443b821df759d468d9d4c3e0515534 Mon Sep 17 00:00:00 2001 From: Nathan Ward Date: Thu, 18 Aug 2022 18:53:08 +0000 Subject: [PATCH] Better error message for `World::resource_scope` (#5727) # Objective - Fixes #5365 - The `assert!()` when the resource from `World::resource_scope` is inserted into the world is not descriptive. ## Solution - Add more context to the assert inside of `World::resource_scope` when the `FnOnce` param inserts the resource. --- crates/bevy_ecs/src/world/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 314bea0d4d82b..661ef2ddd5813 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -1111,7 +1111,10 @@ impl World { }, }; let result = f(self, value_mut); - assert!(!self.contains_resource::()); + assert!(!self.contains_resource::(), + "Resource `{}` was inserted during a call to World::resource_scope.\n\ + This is not allowed as the original resource is reinserted to the world after the FnOnce param is invoked.", + std::any::type_name::()); let resource_archetype = self.archetypes.resource_mut(); let unique_components = resource_archetype.unique_components_mut();