Skip to content

Enable dynamic triggers for observers#23870

Open
dlom wants to merge 1 commit intobevyengine:mainfrom
dlom:mold/dynamic-observer-triggers
Open

Enable dynamic triggers for observers#23870
dlom wants to merge 1 commit intobevyengine:mainfrom
dlom:mold/dynamic-observer-triggers

Conversation

@dlom
Copy link
Copy Markdown

@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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant