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.
This commit is contained in:
Nathan Ward 2022-08-18 18:53:08 +00:00
parent 00508d110a
commit 00323b3048

View file

@ -1111,7 +1111,10 @@ impl World {
},
};
let result = f(self, value_mut);
assert!(!self.contains_resource::<R>());
assert!(!self.contains_resource::<R>(),
"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::<R>());
let resource_archetype = self.archetypes.resource_mut();
let unique_components = resource_archetype.unique_components_mut();