#Required Components vs. Bundles

1 messages · Page 1 of 1 (latest)

unkempt acorn
#

Required components are super cool. This is more of an architectural question, but I'm curious how they should co-exist alongside bundles.
Do they make bundles obsolete, or are bundles still a valid tool in our toolbox? Are they planned to be deprecated entirely in future?
If not, when should the user prefer to use Bundles vs. Required Components?

#

Also is there a way to parameterize the construction of the required components? I used MyBundle::new(...) to do this. But required components can only be initialized via static functions (AFAIK!). Is that a valid use case for bundles, or is there a way to do it via required components?

inland fable
#

afaik, bundles will always stick around as a concept, as any tuple of components is a bundle in itself

unkempt acorn
#

I realize that, but I can't pass those params at runtime, can I?

#

For example:

struct AppleBundle {
    name: Name,
    apple: Apple,
}

impl AppleBundle {
    fn new(name: impl Into<Name>) -> Self { ... }
}
inland fable
#

no, indeed. You could go around that by using on_insert component hooks or observers, but that depends on the scale of what you plan to do

#

Construction methods are still fine as a concept, and you could do it plenty of ways, even without using bundles

#

But for your central question, I guess I don't have enough use of the required components to be 100% sure myself. I guess it's more of an issue when you design APIs in crates, where using bundles can get annoying

#

for example if a bundle contains Transform, you can't add it alongside it if I remember correctly

unkempt acorn
inland fable
unkempt acorn
#

Ahhh I see

inland fable
#

I guess I prefer it being an action that is applied to an entity, rather than a struct (the bundle) which feels more opaque

unkempt acorn
#

I still like being able to use Bundle::new for my prefabs. Cause then I can encapsulate them in factories. In theory I could encapsulate the create_stuff function too...but still

#

My worry is that they'll deprecate bundles in future. So that's the other question I have. Would bundles be obsolete with Required Components, or should we still use them if appropropriate?

inland fable
#

well maybe an expert can correct me on this, but while named bundles (like TransformBundle) have been deprecated, the fundamental concept of a bundle is still pretty important to the engine, as things like commands.spawn((A, B)) uses a bundle in of itself (the tuple)

#

quoting from the 0.15 release blog post:

#

What is happening to Bundles?

The Bundle trait will continue to exist, and it is still the fundamental building block for insert APIs (tuples of components still implement Bundle). Developers are still free to define their own custom bundles using the Bundle derive. Bundles play nicely with Required Components, so you can use them with each other.