Skip to content

Commit

Permalink
Event mutator release notes (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile authored Oct 31, 2024
1 parent 3bd3a4c commit 6f0b9cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,28 @@
<!-- https://github.com/bevyengine/bevy/pull/13818 -->

<!-- TODO -->

When working with complex event-driven logic, you may find that you want to conditionally modify events without changing their type or re-emitting them.
While this has always been possible, it was quite onerous:

```rust
// We need to manually track which events this system has read
// using a system-local `EventCursor`, previously called `ManualEventReader`.
fn mutate_events(mut events: ResMut<Events<MyEvent>>, mut local_cursor: Local<EventCursor<MyEvent>>){
for event in local_cursor.read_mut(&mut *events){
event.mutate();
}
}
```

Now, you can simply use the new [`EventMutator`] system param, which keeps track of this bookkeeping for you.

```rust
fn mutate_events(mut event_mutator: EventMutator<MyEvent>>){
for event in event_mutator.read(){
event.mutate();
}
}
```

[`EventMutator`]: https://docs.rs/bevy/0.15/bevy/ecs/event/struct.EventMutator.html
5 changes: 2 additions & 3 deletions release-content/0.15/release-notes/_release-notes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prs = [14071]
file_name = "14071_Uniform_mesh_sampling.md"

[[release_notes]]
title = "Created an EventMutator for when you want to mutate an event before reading"
title = "`EventMutator`"
authors = ["@BobG1983"]
contributors = ["@atornity", "@alice-i-cecile"]
prs = [13818]
Expand Down Expand Up @@ -453,8 +453,7 @@ file_name = "15800_Add_mesh_picking_backend_and_MeshRayCast_system_parameter.md"

[[release_notes]]
title = "Required Components"
authors = ["@cart",]
authors = ["@cart"]
contributors = ["@alice-i-cecile", "@killercup", "@BD103"]
prs = [14791]
file_name = "14791_Required_Components.md"

0 comments on commit 6f0b9cd

Please sign in to comment.