-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Comments
I wonder if it would be possible to cheat a little bit, by making the default Bundles |
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: |
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 |
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 |
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. |
Fixed by #2254! |
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.
The text was updated successfully, but these errors were encountered: