Skip to content

"Run once" Scenes#23880

Merged
cart merged 9 commits intobevyengine:mainfrom
cart:run_once_scenes
Apr 20, 2026
Merged

"Run once" Scenes#23880
cart merged 9 commits intobevyengine:mainfrom
cart:run_once_scenes

Conversation

@cart
Copy link
Copy Markdown
Member

@cart cart commented Apr 18, 2026

Objective

Scene and SceneList currently require "repeatability". This puts some burden on developers setting "field patches" in BSN, as the "right hand side" values must either be Copy or have a manual Clone. This results in scenes like:

let mesh = meshes.add(Circle::new(4.0));
let material = materials.add(Color::WHITE);

bsn! {
    Mesh3d({mesh.clone()})
    MeshMaterial3d::<StandardMaterial>({material.clone()})
}

In practice, thanks to inheritance caching, repeatability is no longer required.

Solution

  • Make Scene and SceneList consume self.
  • Add SceneBox and SceneListBox subtraits to enable Box<dyn Scene> to impl Scene and consume itself.
  • Switch to FnOnce for patches.

This enables the following code to work:

let mesh = meshes.add(Circle::new(4.0));
let material = materials.add(Color::WHITE);

bsn! {
    Mesh3d(mesh)
    MeshMaterial3d::<StandardMaterial>(material)
}

@cart cart added this to the 0.19 milestone Apr 18, 2026
@cart cart added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Composing and serializing ECS objects labels Apr 18, 2026
@github-actions

This comment was marked as resolved.

@cart cart marked this pull request as draft April 19, 2026 00:39
@alice-i-cecile alice-i-cecile added 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-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Apr 19, 2026
Comment thread crates/bevy_scene/src/scene.rs Outdated
@cart cart marked this pull request as ready for review April 19, 2026 20:59
@cart cart removed the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label Apr 19, 2026
@cart cart marked this pull request as draft April 19, 2026 21:02
@cart cart marked this pull request as ready for review April 19, 2026 21:29
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 20, 2026
Comment thread crates/bevy_scene/src/scene.rs Outdated
Comment thread crates/bevy_scene/src/scene.rs
Comment thread crates/bevy_scene/src/scene.rs
Comment thread crates/bevy_scene/src/scene_list.rs
Comment thread crates/bevy_scene/src/scene_patch.rs Outdated
Copy link
Copy Markdown
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.

Approved with minor feedback. Feel free to fix or ignore.

The elimination of the clones in your sample code really clearly highlights the value here.

@alice-i-cecile alice-i-cecile requested a review from kfc35 April 20, 2026 22:23
Copy link
Copy Markdown
Contributor

@MalekiRe MalekiRe left a comment

Choose a reason for hiding this comment

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

The code LGTM on a functional level

@cart cart removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 20, 2026
@cart cart added this pull request to the merge queue Apr 20, 2026
Merged via the queue into bevyengine:main with commit f135b2b Apr 20, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects 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 X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants