Skip to content

"with_children" does not support adding single component #277

Closed
@Raytwo

Description

@Raytwo

Currently, the implementation requires that the component being spawned implemented DynamicBundle, so you can't do something like this:

fn setup(
    mut commands: Commands,
) {
    commands
        // Player
        .spawn(SpriteComponents {
            material: materials.add(Color::rgb(0.5, 0.0, 0.0).into()),
            translation: Translation(Vec3::new(window_desc.width as f32 / 2.0, 50.0, 0.0)),
            sprite: Sprite {
                size: Vec2::new(30.0, 30.0),
            },
            ..Default::default()
        })
        .with(Player::new())
        .with_children(|parent| {
            parent.spawn(BulletEmitter::new());
        });
}

Instead, you need to do it that way:

.with_children(|parent| {
            parent.spawn( (BulletEmitter::new(), ) );
        });
}

While this is a decent workaround, could it be possible to make it so you can use a regular Component too?

A friend suggested implementing the following, although I'm not knowledgeable about Rust enough to do so myself:
DynamicBundle for T: Component

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions