Skip to content

Allowing using ChildOf directly inside bsn! macro#23921

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
eckz:child-of-template
Apr 21, 2026
Merged

Allowing using ChildOf directly inside bsn! macro#23921
alice-i-cecile merged 2 commits intobevyengine:mainfrom
eckz:child-of-template

Conversation

@eckz
Copy link
Copy Markdown
Contributor

@eckz eckz commented Apr 21, 2026

Objective

If I want to spawn a scene as a child of an entity that already exists, the current api doesn't offer an straightfoward solution.

The easies I found is by doing something like this:

const my_entity = ...;
commands.spawn_scene(bsn! {
    template(move |_| Ok(ChildOf(my_entity)))
    scenes::list_item(text)
});

Solution

  • Deriving directly FromTemplate for ChildOf.
  • Adding a new variant to EntityReference.
  • This allows code like this to work directly
fn scene(root: Entity) -> impl Scene {
    bsn! {
        ( #Child1 ChildOf(root) ),
    }
}

Testing

  • Running unit tests locally.

@eckz eckz marked this pull request as ready for review April 21, 2026 15:36
@kfc35 kfc35 added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Composing and serializing ECS objects D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 21, 2026
Copy link
Copy Markdown
Member

@cart cart left a comment

Choose a reason for hiding this comment

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

This is a good call! Same general ideal as HandleTemplate::Handle. I renamed EntityReference::SpecificEntity to EntityReference::Entity.

@cart cart added this to the 0.19 milestone Apr 21, 2026
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.

Cool! That's a nice idea. Thanks for adding a test.

@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 Apr 21, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 21, 2026
Merged via the queue into bevyengine:main with commit 6aba995 Apr 21, 2026
40 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-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants