pub struct ChildBundle<B: Bundle>(pub B);
Expand description
A component that, when added to an entity, will add a child entity with the given bundle.
This component will be removed from the entity, as its data is moved into the child entity.
You can add multiple children in this way, if and only if their bundle types are distinct.
See ChildBundles
for a version that supports adding multiple children of the same type.
Under the hood, this is done using component lifecycle hooks.
use bevy_ecs::prelude::*;
use bevy_bundletree::ChildBundle;
#[derive(Component)]
struct A;
#[derive(Component)]
struct B(u8);
fn spawn_hierarchy(mut commands: Commands) {
commands.spawn(
(A, // Parent
ChildBundle( // This component is removed on spawn
(A, B(3)) // Child
)
));
}
Tuple Fields§
§0: B
Trait Implementations§
Source§impl<B: Clone + Bundle> Clone for ChildBundle<B>
impl<B: Clone + Bundle> Clone for ChildBundle<B>
Source§fn clone(&self) -> ChildBundle<B>
fn clone(&self) -> ChildBundle<B>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<B: Bundle> Component for ChildBundle<B>
impl<B: Bundle> Component for ChildBundle<B>
Source§const STORAGE_TYPE: StorageType = StorageType::SparseSet
const STORAGE_TYPE: StorageType = StorageType::SparseSet
This is a sparse set component as it’s only ever added and removed, never iterated over.
Source§fn register_component_hooks(hooks: &mut ComponentHooks)
fn register_component_hooks(hooks: &mut ComponentHooks)
Called when registering this component, allowing mutable access to its
ComponentHooks
.Source§fn register_required_components(
_component_id: ComponentId,
_components: &mut Components,
_storages: &mut Storages,
_required_components: &mut RequiredComponents,
_inheritance_depth: u16,
)
fn register_required_components( _component_id: ComponentId, _components: &mut Components, _storages: &mut Storages, _required_components: &mut RequiredComponents, _inheritance_depth: u16, )
Registers required components.
Auto Trait Implementations§
impl<B> Freeze for ChildBundle<B>where
B: Freeze,
impl<B> RefUnwindSafe for ChildBundle<B>where
B: RefUnwindSafe,
impl<B> Send for ChildBundle<B>
impl<B> Sync for ChildBundle<B>
impl<B> Unpin for ChildBundle<B>where
B: Unpin,
impl<B> UnwindSafe for ChildBundle<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§fn register_required_components(
components: &mut Components,
storages: &mut Storages,
required_components: &mut RequiredComponents,
)
fn register_required_components( components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, )
Registers components that are required by the components in this
Bundle
.Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.