Skip to content

Mutate Event/Hook - #25275

Draft
Diddykonga wants to merge 1 commit into
bevyengine:mainfrom
Diddykonga:query_mutation_events
Draft

Mutate Event/Hook#25275
Diddykonga wants to merge 1 commit into
bevyengine:mainfrom
Diddykonga:query_mutation_events

Conversation

@Diddykonga

@Diddykonga Diddykonga commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Mutate Event/Hook

Objective

Lifecycle Hooks/Events currently cover Immutable Components changing value and changing structurally for all Components, but often times we would like it if it also covered Mutable Components changing value.

So that Lifecycle Hooks/Events cover All Components changing value or structurally.

Solution

Prior PR/Approach: #16143
Arrived at the same solution, didnt actually look at the code.

This approach attempts to give SystemParam::apply/queue the responsibility of triggering/queuing Mutate Events via Change Tick scans of their mutably-accessed Components.

Some things to note:

  1. Mutate Events are grouped by individual SystemParam, which in most cases is fine and leads to normal results, although some wierdness can occur when using a collection of SystemParams that happen to overlap. ex. ParamSet with two identical queries.
  2. The main driver for knowledge of access is, Access, which can contain Unbounded acessess's (ex. EntityMutExcept<...>). In these cases we are not given any definite knowledge as to what was accessed and what wasn't so we must scan every component, except the ones excluded if any.

Impled for Query, Single, Populated, ResMut, FilteredResourcesMut.

Testing

  • Did you test these changes? If so, how? Barely, just ran bevy_city with and without. I'm not a good tester.
  • Are there any parts that need more testing? All of it, please.

Showcase

fn mutate_observer(mutate: On<Mutate>) {
    let entity = mutate.entity;
    let components = &mutate.components;
    println!("{mutate:?}");
}

fn mutate_component_observer(mutate: On<Mutate, Transform>) {
    let entity = mutate.entity;
    let components = &mutate.components;
    println!("{mutate:?}");
}

#[derive(Component)]
struct MyComponent {
    // ...
}

impl MyComponent {
    fn on_mutate(mut world: DeferredWorld, hook: HookContext) {
        // ...
    }
}

Mutate Event/Hook
@JaySpruce JaySpruce added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Aug 6, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants