bsn: Silent failure when adding multiple entity references, in which one is assigned to a `SceneComponent` property of type `Box<dyn SceneList>`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version and features
`bevy = { version = "0.19.1", features = ["dynamic_linking", "bevy_text", "ui"] }`
## What you did
The below code is a minimal reproduceable example of an issue I encountered while working with `FeathersMenu` and `FeathersMenuButton` and specifically the `@caption` property of the latter.
It seems when the parent has an entity reference, AND the bsn assigned to the caption also has an entity reference, something fails under the hood, causing the entire entity to not be added, and no error is produced.
```rust
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
//
.add_systems(Startup, setup)
.add_systems(Startup, scene.spawn())
//
.run();
}
fn setup(
mut commands: Commands,
) {
commands.spawn(Camera3d::default());
}
pub fn scene() -> impl SceneList {
bsn! {
Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
row_gap: px(8),
}
Children [
Text("start"),
@TestMainComponentWithCaptionRef,
Text("end"),
]
}
}
struct TestSubComponentProps {
caption: Box
}
impl Default for TestSubComponentProps {
fn default() -> Self {
TestSubComponentProps {
caption: Box::new(bsn!{})
}
}
}
#[derive(SceneComponent, Clone, Default)]
#[scene(TestSubComponentProps)]
struct TestSubComponent;
impl TestSubComponent {
fn scene(props: TestSubComponentProps) -> impl Scene {
bsn! {
Node
Children [
{props.caption}
]
}
}
}
#[derive(SceneComponent, Clone, Default)]
struct TestMainComponentWithCaptionRef;
impl TestMainComponentWithCaptionRef
{
fn scene() -> impl Scene {
bsn! {
#MainTest
Node
Children [
@TestSubComponent {
@caption: bsn! { Text("Test") #CaptionTest },
},
]
}
}
}
```
## What went wrong
`@TestMainComponentWithCaptionRef` is not added as an entity
## Additional information
It's the specific configuration above, where both `#MainTest` and `#CaptionTest` exist, that seems to trigger the issue. Make any of the following changes and works as expected:
1. Remove `#MainTest` or `#CaptionTest`
2. Change #MainTest or #CaptionTest to use `Name(...)` .
3. Change the assignment of caption from:
`bsn! { Text("Test") #CaptionTest },`
to:
`{ Box::new(bsn! { Text("Test") #CaptionTest }) as Box }`
Contributor guide
Research direction
Start by running the minimal reproduction using the bsn! macro, SceneComponent, SceneList, and scene.spawn() shown in the issue. Trace the scene-building path for the parent and caption entity references, then verify that the parent entity is added when both #MainTest and #CaptionTest are present without producing an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100