Skip to content

Render events - #18517

Closed
ecoskey wants to merge 8 commits into
bevyengine:mainfrom
ecoskey:render_events
Closed

ecoskey wants to merge 8 commits into
bevyengine:mainfrom
ecoskey:render_events

Conversation

@ecoskey

@ecoskey ecoskey commented Mar 24, 2025 •

Copy link
Copy Markdown
Contributor

Objective

fix #18491 (comment)
Sometimes users want to send events from the render world to the main world. While not often advised, some advanced use-cases like readback use a similar pattern, which often requires setting up a channel and relaying events manually.

Solution

Add a simple abstraction (App::init_render_event) to set up the channel and relay events to the main world, retaining caller information.

Note: this pr makes Events::send_with_caller public, but does not add a similar public method on EventWriter

Testing

Ran example

@github-actions

Copy link
Copy Markdown
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@ecoskey
ecoskey requested a review from IceSentry March 24, 2025 17:52
@ecoskey ecoskey added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 24, 2025
Comment thread examples/shader/render_event.rs Outdated
@JMS55

JMS55 commented Mar 24, 2025

Copy link
Copy Markdown
Contributor

Quickly leaving my thoughts, I don't love the events naming.

It has nothing to do with events about rendering, but is just an arbitrary channel for sending data back to the main world, right?

Not sure what a better name is though, and again haven't looked at the PR to deeply yet.

@IceSentry

Copy link
Copy Markdown
Contributor

They are events from the render world. I think it's fair to call them render event. Presumably, users will need this to send events in the context of rendering. Otherwise they wouldn't need events sent from the render world. Maybe specify render world event just to remove any possible ambiguity, but I'm not sure what kind of ambiguity there could be.

@ecoskey ecoskey added this to the 0.17 milestone Apr 10, 2025
Comment on lines +38 to +45
let send_render_event = (
ParamBuilder,
ParamBuilder,
ParamBuilder,
LocalBuilder(Timer::from_seconds(2.0, TimerMode::Repeating)),
)
.build_state(render_app.world_mut())
.build_system(send_render_event);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels a bit unnecessarily complex. I'd suggest using a resource instead just because that's a more common ECS api.

@tychedelia tychedelia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Think formalizing this makes sense versus ad hoc. 👍


use crate::RenderApp;

pub trait RenderEventApp {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure what our convention is here -- should this be in the prelude so it doesn't have to be imported?

///
/// Internally, this struct writes to a channel, the contents of which are relayed
/// to the main world's [`Events`] stream during [`PreUpdate`]. Note that because
/// the render world is pipelined, the events may not arrive before the next frame begins.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They almost certainly will not, but they also could. I think we might want to be clearer about how this works. In practice, you'll receive events from rendering frame N-2 with respect the the main world, but that isn't guaranteed. Users should supply their own temporal correlation id if necessary.

@@ -0,0 +1,90 @@
//! Simple example demonstrating the use of [`App::init_render_event`] to send events from the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be expanded to say, in effect, "you probably don't want to do this."

@tychedelia tychedelia 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 21, 2025

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Broadly on-board with this pattern and it existing, but I think we need to clean this up before merging.

Key things:

  • the system builder in the example is too complicated and distracts from the point of the example
  • the example description needs to be expanded to give more context
  • this needs a non "Event" naming scheming to avoid confusion. Maybe something with "channel" in it?

Long-term, this should be baked into a multi-world ECS design, and not need channels, but formalizing this pattern in some form is a good way to gather requirements and ease refactoring.

@ecoskey ecoskey added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels May 19, 2025
@alice-i-cecile alice-i-cecile removed this from the 0.17 milestone Jul 28, 2025
@alice-i-cecile

Copy link
Copy Markdown
Member

Cut from the milestone: this would be nice to have but shouldn't block Bevy 0.17's release.

@ecoskey

ecoskey commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

closing, stale.

@ecoskey ecoskey closed this Dec 14, 2025
@ecoskey
ecoskey deleted the render_events branch December 18, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Send events from the render world to the main world

5 participants