-
-
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
Merge bundles together #792
Comments
While this is being looked at, it might be useful to think about how we can flatten nested bundles. Bundles which contain a |
In Discord, there was discussion of an alternate method to solve this problem: simply flattening the bundles entirely. On the face of it, to make this non-ambiguous, you'd have to disallow non-bundle tuple components. I'm not convinced this is a huge loss. They're a very strange way of thinking about components; I think specialization is better handled by making the component type generic and I don't see any other obvious uses. |
To demonstrate a particular example of this problem, here's an example showing the painful interaction between Suppose we're adding a number of entities at once with .spawn_batch((0..1_000).map(|_| Bundle {
pos: Position(0.0),
vel: Velocity(0.0),
})) If we also want to add a .spawn_batch((0..1_000).map(|_| Bundle {
pos: Position(0.0),
vel: Velocity(0.0),
ball: Ball(),
})) But if we're using a premade bundle, like A method for |
I think a good and more intuitive solution would be moving the EDIT: I think besides a more consistent code base, having the with on the bundle will allow you to separate the |
@RustyStriker I think your proposed solution will still require some kind of "flattening" operator. struct With<B: Bundle, C: Component>(B, C)
impl Bundle for With { ... }
trait Bundle {
...
fn with<C: Component>(Self, component: C) -> With<Self, C>
} Since the I was just taking a look at implementing some kind of flatten attribute: #[derive(Bundle)]
struct MyBundle {
#[flatten] sprite: SpriteBundle
other: OtherComponent,
} Right now, it seems like actually implementing I think the |
I believe the Bevy ECS rewrite I'm wrapping up will make this sort of thing much easier. The Bundle api is much simpler now. |
This is (maybe) planned for #1525, and if not, should be much easier to implement once it's merged. |
I think theres still value in the "bundle builder" apis mentioned above. #1525 adds the ability to nest bundle types, but more dynamic |
Yes it looks like it is solved by #1525. I still think there is value in ad hoc composition here using something like |
Personally I don't think this is very useful since you could just do |
And hopefully the same thing with commands shortly too. But there's a reasonably important use case I think you're missing @TheRawMeatball: bundle builder functions that are nested a couple layers deep. These have cropped up for me a few times, where:
Moreover, bundles will be getting many more uses with #1481, better scenes and so on, so adding a few core QoL methods like this will pay off there too. Is there some appropriate collections trait we can impl for bundles? That really feels like the most idiomatic solution here: it's very strange to have something close to a Vec of components that doesn't behave at all like one. |
@TheRawMeatball As I showed in my initial issue, that doesn't work in some special cases.
I think @alice-i-cecile has listed off more cases in newer/upcoming versions. But I'd like to approach this from another angle. Having ad-hoc bundles is useful for many of the same reasons why tuples are useful. When you need to package multiple things together, but you don't want to give them a name. Either because it's verbose, or because there isn't a great name to give them. @alice-i-cecile No, I don't believe there are any standard collection traits. If this feels like a |
Isn't this issue obsoleted by |
It helps, but doesn't solve it. You can do that to define bundles, but not to work with them dynamically. |
Ohhhh, right dang. |
Following #2975, this seems to be resolved as you can now just use tuple bundles to group multiple bundles and components together. fn test(mut commands: Commands) {
commands.spawn((
Camera3dBundle::default(),
TransformBundle::default(),
SpriteBundle::default()
));
} |
I ran into an issue using
Commands::spawn_batch
to spawn in a bunch of entities that have some custom components and also needed aSpriteComponents
bundle for rendering, and the only way I could find to do this was to usecommands.spawn(...).with_bundle(...)
or inline the fields ofSpriteComponents
. Both of these are sub-optimal solutions in my eyes.One way to solve this would be to add a combinator for
Bundle
likesuch that
This would allow you to combine bundles in places where you can only pass in a single bundle, for example
Commands::spawn_batch
.The text was updated successfully, but these errors were encountered: