Skip to content

Instantly share code, notes, and snippets.

@RJ
Last active September 3, 2024 07:49
Show Gist options
  • Save RJ/c746cf782f6b9dc4022498d44de38013 to your computer and use it in GitHub Desktop.
Save RJ/c746cf782f6b9dc4022498d44de38013 to your computer and use it in GitHub Desktop.
return a system from a function, enclosing something useful
/*
Sometimes you want to dump some component values in multiple different schedules
like when debugging network replication..
here's an example of a function you can use to enclose the schedule name you put it in:
```rust
app.add_systems(Update, dumper("Update"));
app.add_systems(Last, dumper("Last"));
```
*/
fn dumper(name: &str) -> bevy::ecs::schedule::SystemConfigs {
let name = String::from(name);
(move |q: Query<(Entity, &Position, &Transform), With<Player>>, tick_manager: Res<TickManager>| {
let tick = tick_manager.tick();
for (e, pos, trans) in q.iter() {
info!("{name} @ {tick:?} {e:?} {pos:?} {trans:?}");
}
})
.into_configs()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment