Skip to content

Enable dynamic triggers for observers#23870

Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom
dlom:mold/dynamic-observer-triggers
Apr 19, 2026
Merged

Enable dynamic triggers for observers#23870
alice-i-cecile merged 1 commit intobevyengine:mainfrom
dlom:mold/dynamic-observer-triggers

Conversation

@dlom
Copy link
Copy Markdown
Contributor

@dlom dlom commented Apr 18, 2026

Objective

Finish the bevy_ecs dynamic story. Currently you can register observers with dynamic triggers and runners, but there's no way to actually trigger these observers dynamically.

Solution

Adds three new unsafe World functions:

  • trigger_dynamic()
  • trigger_dynamic_targets()
  • trigger_dynamic_targets_components()

These enable observers to be triggered with untyped events and trigger data. Their implementations are just wiring up some existing internal structure. Structurally, they are based on their non-dynamic counterparts.

Also exposes EventKey::new() and EventKey::component_id() for constructing event keys from dynamic ComponentIds.

Testing

Several new tests

Showcase

See updated example

assert_eq!(vec!["event_a"], world.resource::<Order>().0);
}

/// Collects `u32` values read by dynamic observers through `PtrMut`.
Copy link
Copy Markdown
Contributor Author

@dlom dlom Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next 250 lines are all the new tests

Adds three new unsafe `World` functions:
- `trigger_dynamic()`
- `trigger_dynamic_targets()`
- `trigger_dynamic_targets_components()`

These enable observers to be triggered with untyped events and trigger
data. Their implementations are just wiring up some existing internal
structure. Structurally, they are based on their non-dynamic counterparts.

Also exposes `EventKey::new()` and `EventKey::component_id()` for
constructing event keys from dynamic `ComponentId`s.

Extends the dynamic example with event registration and triggering.
@dlom dlom force-pushed the mold/dynamic-observer-triggers branch from 23efde4 to 38cb1d4 Compare April 18, 2026 07:41
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy A-ECS Entities, components, systems, and events X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 18, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Apr 18, 2026
@alice-i-cecile alice-i-cecile requested a review from mockersf April 19, 2026 00:38
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 19, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 19, 2026
Merged via the queue into bevyengine:main with commit 334c242 Apr 19, 2026
54 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in ECS Apr 19, 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-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Trivial Nice and easy! A great choice to get started with Bevy D-Unsafe Touches with unsafe code in some way S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants