pub struct DynamicBundle {
components: Vec<BundleComponent>,
name: &'static str,
}Expand description
A bundle assembled at runtime.
This is what crate::bundle! writes and what a Bundle implementation
builds its components into. A type of the caller’s own is the usual way to
spawn an object; reach for this one when the components are only known once
the program runs.
It also carries the name of the entity it will spawn, which by default is the
source position of the crate::bundle! that built it.
Fields§
§components: Vec<BundleComponent>§name: &'static strImplementations§
Source§impl DynamicBundle
impl DynamicBundle
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty bundle with no name, for one built by hand.
crate::bundle! is what supplies a name, so a bundle filled in by
hand names its entity after nothing: give it one with
DynamicBundle::named, or spawn it with
ScopeMut::spawn_named.
Sourcepub fn named(self, name: &'static str) -> Self
pub fn named(self, name: &'static str) -> Self
Name the bundle, replacing the one crate::bundle! gave it.
crate::bundle! names every bundle it builds after the source
position that wrote it, and a spawn gives that name to the entity. A
bundle assembled at runtime has no such position to speak of, so it
names itself here instead.
Sourcepub fn push_component<C: 'static>(&mut self, value: C)
pub fn push_component<C: 'static>(&mut self, value: C)
Add one component.
The value is stored under its own type, so a tuple pushed here stays one component.
Sourcepub fn push_bundle<B: Bundle>(&mut self, bundle: B)
pub fn push_bundle<B: Bundle>(&mut self, bundle: B)
Add every component of bundle to this one.
This is how a caller gathers several bundles into one spawn: the components keep their own types, so a bundle that holds a tuple contributes that tuple as a single component, exactly as spawning it alone would.
Sourcepub(crate) fn finish(self) -> Vec<BundleComponent>
pub(crate) fn finish(self) -> Vec<BundleComponent>
The components in type order.
§Panics
When the same component appears twice. The duplicate is caught here rather than at spawn so that every path into an archetype, queued or immediate, reports it from the call that wrote the bundle.