Skip to content

Thoroughly document the current state of observers #19590

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

Merged
merged 19 commits into from
Jun 11, 2025

Conversation

alice-i-cecile
Copy link
Member

Objective

The documentation for observers is not very good. This poses a problem to users, but also causes serious problems for engine devs, as they attempt to improve assorted issues surrounding observers.

This PR:

To keep this PR at all reviewable, I've opted to simply note the various limitations (some may call them bugs!) in place, rather than attempting to fix them. There is a huge amount of cleanup work to be done here: see Alice's Work Planning.

Solution

  • Write good module docs for observers, offering bread crumbs to the most common methods and techniques and comparing-and-contrasting as needed.
  • Fix any actively misleading documentation.
  • Try to explain how the various bits of the (public?!) internals are related.

@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jun 11, 2025
@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation 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 S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 11, 2025
Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

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

lgtm. minor suggestions and comments

//! By contrast, [`EventReader`] and [`EventWriter`] ("buffered events"), are pull-based.
//! They require periodically polling the world to check for new events, typically in a system that runs as part of a schedule.
//!
//! This imposes a small overhead, making observers a better choice for extremely rare events,
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to quantify "extremely rare" rather than leaving it up to the user's interpretation. Many users will think of "extremely rare" as a user-driven button click seconds or minutes apart, while others will think of "once every N frames".

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! But I don't have any benches to provide guidance here right now.

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Did a pass over the module-level docs. Some code examples would be nice to demonstrate how to actually write/spawn/trigger observers.

//! ## Observer timing
//!
//! Observers are triggered via [`Commands`], which imply that they are evaluated at the next sync point in the ECS schedule.
//! Accordingly, they have full access to the world, and are evaluated sequentially, in the order that the commands were sent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Fun anecdote: During the game jam, I had a case where I was using Commands (let's call this C1) to trigger an observer in a system that also had a custom SystemParam that had its own Commands (C2). Not thinking about it too much, I used C1, then called a method that internally used C2, and then afterwards used C1 again. But because these were separate command queues, the execution order was actually either C1 C1 C2 or C2 C2 C1, which in this scenario caused a logic bug that gave me infinite recursion! This one was fun to track down :P

alice-i-cecile and others added 4 commits June 11, 2025 17:06
Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
@alice-i-cecile alice-i-cecile requested a review from Jondolf June 11, 2025 21:53
@Jondolf Jondolf 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 Jun 11, 2025
@alice-i-cecile alice-i-cecile enabled auto-merge June 11, 2025 22:02
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 11, 2025
Merged via the queue into bevyengine:main with commit 12f8f9c Jun 11, 2025
33 of 34 checks passed
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-Docs An addition or correction to our documentation D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes 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
None yet
5 participants