Skip to content
Discussion options

You must be logged in to vote

Your question is actually two questions, so here are the answers

How to access multiple resources mutably at the same time on a &mut World

There is two ways to go about it:

  1. resource_scope method on World.
world.resource_scope(|world, mut a: Mut<A>| {
    let b = world.get_mut::<B>(entity).unwrap();
    a.0 += b.0;
});

This incurs rightward drift, but it's the quick and dirty solution

  1. Use SystemState to "emulate" a system parameter-style interface.
let mut system_state: SystemState<(
    EventWriter<MyEvent>,
    Option<ResMut<MyResource>>,
    Query<&MyComponent>,
    )> = SystemState::new(&mut world);
let (event_writer, maybe_resource, query) = system_state.get_mut(&mut world);

I fin…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@bcolloran
Comment options

@bcolloran
Comment options

@hymm
Comment options

hymm Oct 14, 2022
Collaborator

Answer selected by bcolloran
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants