Skip to content

How to bypass "duplicate" state access to modify state in multiple systems? #18101

Answered by jfouche
Rratic asked this question in Q&A
Discussion options

You must be logged in to vote

The problem comes from the fact the world: &World, mut commands: Commands, mut next_state: ResMut<NextState<ProcessState>>, system params :

  • world: &World implies a read only lock to the whole world
  • mut next_state: ResMut<NextState<ProcessState>> implies a exclusive write access to the NextState<ProcessState> resource, which is part of the world

So you break the Rust rules on references (either one mutable reference or any number of immutable references) on a resource.

The question is why do you need an acces to the whole World instead of using Query<> or Res<> system params ? An access to &World will block all other systems that need an mutable acces to a part of the world to run in par…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@Rratic
Comment options

Comment options

You must be logged in to vote
1 reply
@Rratic
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Rratic
Comment options

@jfouche
Comment options

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