Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SceneInstanceReady to trigger an observer. #13859

Merged
merged 4 commits into from
Jul 30, 2024

Conversation

komadori
Copy link
Contributor

@komadori komadori commented Jun 15, 2024

Objective

The SceneInstanceReady event would be more ergonomic (and potentially efficient) if it could be delivered to listeners attached to the scene entities becoming ready rather than into a World-global queue.

This is an evolution of @Shatur's work in #9313.

Solution

The scene spawner is changed to trigger observers on the scene entity when it is ready rather than enqueue an event with EventWriter.

This addresses the two outstanding feature requests mentioned on #2218, that i) the events should be "scoped" in some way and ii) that the InstanceId should be included in the event.

Testing

Modified the scene_spawner::tests::event test to use the new mechanism.


Changelog

  • Changed SceneInstanceReady to trigger an entity observer rather than be written to an event queue.
  • Changed SceneInstanceReady to carry the InstanceId of the scene.

Migration Guide

If you have a system which read SceneInstanceReady events:

fn ready_system(ready_events: EventReader<'_, '_, SceneInstanceReady>) {

It must be rewritten as an observer:

commands.observe(|trigger: Trigger<SceneInstanceReady>| {

Or, if you were expecting the event in relation to a specific entity or entities, as an entity observer:

commands.entity(entity).observe(|trigger: Trigger<SceneInstanceReady>| {

@janhohenheim janhohenheim added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Serialized ECS data stored on the disk M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide X-Contentious There are nontrivial implications that should be thought through D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 17, 2024
Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

This makes a lot of sense. Could you add some documentation to SceneInstanceReady describing how to interact with it now?

@komadori
Copy link
Contributor Author

This makes a lot of sense. Could you add some documentation to SceneInstanceReady describing how to interact with it now?

@janhohenheim Good idea. I feel that "triggered" is the right verb for observers instead of "emitted". I added bevy_ecs::observer::Trigger to the see also section.

/// Triggered on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use.

Alternatively, this just occurred to me, I could rewrite it as follows and work the word "observer" in there but I think it's a bit more cumbersome:

/// A [`Trigger`] for observers on a scene's parent entity when [`crate::SceneInstance`] becomes ready to use.

@janhohenheim
Copy link
Member

@alice-i-cecile do we have some guideline for how to document something triggering observers?

@alice-i-cecile
Copy link
Member

Not yet!

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I agree: observers are a much nicer pattern here.

@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 Jul 14, 2024
@alice-i-cecile
Copy link
Member

@komadori merge conflicts are non-trivial. Can you please resolve them and then ping me? <3 I'd like to merge this in.

@alice-i-cecile alice-i-cecile added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Jul 15, 2024
@alice-i-cecile alice-i-cecile removed the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jul 22, 2024
@komadori
Copy link
Contributor Author

@alice-i-cecile I've merged in main. The conflicts were caused by #11741 adding more situations in which the SceneInstanceReady event was sent. I've converted events from parent-less scene spawns into non-targeted observer triggers. Added more tests for dynamic scenes.

@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-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jul 30, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Fantastic work: I'm quite pleased with the end result.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 30, 2024
Merged via the queue into bevyengine:main with commit 3d1c9ca Jul 30, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants