bevy_ggrs icon indicating copy to clipboard operation
bevy_ggrs copied to clipboard

Avoid triggering `Added` and `Changed` queries on all rollbacks?

Open johanhelsing opened this issue 1 year ago • 5 comments

When a rollback is triggered, bevy_ggrs restores a saved world snapshot. It updates components by first removing them, and then adding them again. This triggers all queries with Added<Component> or Changed<Component> in it, regardless of whether the component was already there and whether it changed.

https://github.com/gschup/bevy_ggrs/blob/b730a0b1a765bca2cb79466c36d86cac08ae1a12/src/world_snapshot.rs#L177

Sometimes systems have queries that react to other components being added or changed, triggering changes on every rollback. Sometimes, this just causes a small performance hit, other times, it leads to buggy behavior because setup code runs multiple times.

Describe the solution you'd like Perhaps it's possible to only update the component if it's different?

Additional context In regular game code, this is usually quite easy to fix or work around, but sometimes the affected code belongs to 3rd party crates, which are a lot harder to solve.

johanhelsing avatar Dec 11 '22 14:12 johanhelsing