You could try removing the component all together by making an exclusive system that gets the world's components and storages and try to remove the stuff corresponding to your component. However, this entails transmuting &Components
to &mut Components
(unless there is some other way to get the mutable Components
field in World
), which is UB. This is a very bad idea and should not be done, but is possible.
Personally, I think you are doing something wrong by making a type that only exists for a moment. I could be wrong about your use case (it would have been nice if you provided it), but something like a resource can be removed easily via commands.remove_resource
, in which you can store a table of entities and their associated value. Maybe this won't work, but I'm sure there is an alternative.
Here is the appropriate way to remove all components (just for reference):
fn delete_components(mut commands: Commands, query: Query<Entity, With<YourComponent>> {
{ // put your condition here
// or if the component is not needed after a stage in startup,
// you could make this system a startup system after that stage
for entity in query.iter() {
commands.entity(entity).remove::<YourComponent>();
}
}
}