Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding bundle as a single component instead of silently failing #392

Closed
zenMaya opened this issue Aug 30, 2020 · 6 comments
Closed
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@zenMaya
Copy link

zenMaya commented Aug 30, 2020

When you want to add *Components, you must use .spawn(*Components) and not .spawn((*Components, ..)) the spawning will fail, but there is no indication to the user, that it won't work.

This is also the case when adding .with(*Components) instead of .with_bundle(*Components)

This should definitely tell user, that it's not correct to add bundles this way and not silently fail but compile no problem.

@DJMcNab
Copy link
Member

DJMcNab commented Aug 30, 2020

I wonder if it would be possible to cheat a little bit, by making the default Bundles !Sync, maybe by adding a PhantomData<*const ()> field?
Obviously we'd have to change the macros crate to add #[bundle(ignore)].
I'd probably also add #[bundle(optional)] at the same time.
I'm going to do some investigative work around this soon.

@karroffel karroffel added C-Code-Quality A section of code that is hard to understand or change A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible labels Aug 30, 2020
@CleanCut
Copy link
Member

I wasted an hour of my life on this today (again). Can you spot my error?

struct Something;

fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
    commands
        .spawn(Camera2dBundle::default())
        .spawn((Something,))
        .with(Text2dBundle {
            text: Text {
                value: "Some Text".to_string(),
                font: asset_server.load("fonts/FiraSans-Bold.ttf"),
                style: TextStyle {
                    font_size: 60.0,
                    color: Color::WHITE,
                    alignment: TextAlignment {
                        vertical: VerticalAlign::Center,
                        horizontal: HorizontalAlign::Center,
                    },
                },
            },
            ..Default::default()
        });
}

Answer: .with(...) was silently failing. It needed to be .with_bundle(...)

@DJMcNab
Copy link
Member

DJMcNab commented Dec 28, 2020

I've had a new idea of how to 'fix' this, which would be to go super simple

fn illegal_component_system<T: Bundle>(q: Query(Entity, With<T>)){
for e in q.iter(){
 //...print message depending on settings
}
}

And then add a method on app to add this system

Possibly also add a field on App which would disable adding these

@cart
Copy link
Member

cart commented Jan 9, 2021

I've had a new idea of how to 'fix' this, which would be to go super simple

Its a bit heavy for my taste to prevent what in most cases is a "newbie error". And would require somehow connecting the World impl and the Schedule impl to ensure a new system is inserted for each Bundle.

Haha its not a full solve, but we could consider un-implementing Bundle entirely for tuples. (ex: the only way to spawn something is through a pre-constructed Bundle derive, otherwise you must use commands.with())

It doesn't solve the commands.with(SomeBundle) problem though.

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Feb 11, 2021

As part of this, trying to access a bundle as a component (commonly as part of a query) should also fail or warn. See #403 for related work on disambiguating components and bundles.

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed C-Feature A new feature, making something new possible labels Feb 17, 2021
@alice-i-cecile
Copy link
Member

Fixed by #2254!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants