Trait valence::ecs::prelude::Bundle

pub unsafe trait Bundle:
    DynamicBundle
    + Send
    + Sync
    + 'static {
    // Required method
    fn get_component_ids(
        components: &Components,
        ids: &mut impl FnMut(Option<ComponentId>),
    );
}
Expand description

The Bundle trait enables insertion and removal of Components from an entity.

Implementors of the Bundle trait are called ‘bundles’.

Each bundle represents a static set of Component types. Currently, bundles can only contain one of each Component, and will panic once initialised if this is not met.

§Insertion

The primary use for bundles is to add a useful collection of components to an entity.

Adding a value of bundle to an entity will add the components from the set it represents to the entity. The values of these components are taken from the bundle. If an entity already had one of these components, the entity’s original component value will be overwritten.

Importantly, bundles are only their constituent set of components. You should not use bundles as a unit of behavior. The behavior of your app can only be considered in terms of components, as systems, which drive the behavior of a bevy application, operate on combinations of components.

This rule is also important because multiple bundles may contain the same component type, calculated in different ways — adding both of these bundles to one entity would create incoherent behavior. This would be unexpected if bundles were treated as an abstraction boundary, as the abstraction would be unmaintainable for these cases. For example, both Camera3dBundle and Camera2dBundle contain the CameraRenderGraph component, but specifying different render graphs to use. If the bundles were both added to the same entity, only one of these two bundles would work.

For this reason, there is intentionally no Query to match whether an entity contains the components of a bundle. Queries should instead only select the components they logically operate on.

§Removal

Bundles are also used when removing components from an entity.

Removing a bundle from an entity will remove any of its components attached to the entity from the entity. That is, if the entity does not have all the components of the bundle, those which are present will be removed.

§Implementors

Every type which implements Component also implements Bundle, since Component types can be added to or removed from an entity.

Additionally, Tuples of bundles are also Bundle (with up to 15 bundles). These bundles contain the items of the ‘inner’ bundles. This is a convenient shorthand which is primarily used when spawning entities. For example, spawning an entity using the bundle (SpriteBundle {...}, PlayerMarker) will spawn an entity with components required for a 2d sprite, and the PlayerMarker component.

unit, otherwise known as (), is a Bundle containing no components (since it can also be considered as the empty tuple). This can be useful for spawning large numbers of empty entities using World::spawn_batch.

Tuple bundles can be nested, which can be used to create an anonymous bundle with more than 15 items. However, in most cases where this is required, the derive macro Bundle should be used instead. The derived Bundle implementation contains the items of its fields, which all must implement Bundle. As explained above, this includes any Component type, and other derived bundles.

If you want to add PhantomData to your Bundle you have to mark it with #[bundle(ignore)].

use bevy_ecs::{component::Component, bundle::Bundle};

#[derive(Component)]
struct XPosition(i32);
#[derive(Component)]
struct YPosition(i32);

#[derive(Bundle)]
struct PositionBundle {
    // A bundle can contain components
    x: XPosition,
    y: YPosition,
}

// You have to implement `Default` for ignored field types in bundle structs.
#[derive(Default)]
struct Other(f32);

#[derive(Bundle)]
struct NamedPointBundle<T: Send + Sync + 'static> {
    // Or other bundles
    a: PositionBundle,
    // In addition to more components
    z: PointName,

    // when you need to use `PhantomData` you have to mark it as ignored
    #[bundle(ignore)]
    _phantom_data: PhantomData<T>
}

#[derive(Component)]
struct PointName(String);

§Safety

Manual implementations of this trait are unsupported. That is, there is no safe way to implement this trait, and you must not do so. If you want a type to implement Bundle, you must use derive@Bundle.

Required Methods§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl Bundle for ()

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

source§

impl Bundle for BossBarBundle

source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

source§

impl Bundle for PlayerListEntryBundle

source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

source§

impl Bundle for ObjectiveBundle

source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

source§

impl Bundle for WeatherBundle

source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

source§

impl Bundle for WorldBorderBundle

source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0> Bundle for (B0,)
where B0: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1> Bundle for (B0, B1)
where B0: Bundle, B1: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2> Bundle for (B0, B1, B2)
where B0: Bundle, B1: Bundle, B2: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3> Bundle for (B0, B1, B2, B3)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4> Bundle for (B0, B1, B2, B3, B4)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5> Bundle for (B0, B1, B2, B3, B4, B5)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6> Bundle for (B0, B1, B2, B3, B4, B5, B6)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle, B10: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle, B10: Bundle, B11: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle, B10: Bundle, B11: Bundle, B12: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle, B10: Bundle, B11: Bundle, B12: Bundle, B13: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

§

impl<B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14> Bundle for (B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14)
where B0: Bundle, B1: Bundle, B2: Bundle, B3: Bundle, B4: Bundle, B5: Bundle, B6: Bundle, B7: Bundle, B8: Bundle, B9: Bundle, B10: Bundle, B11: Bundle, B12: Bundle, B13: Bundle, B14: Bundle,

§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Implementors§

source§

impl Bundle for ClientBundle

§

impl Bundle for AllayEntityBundle

§

impl Bundle for AreaEffectCloudEntityBundle

§

impl Bundle for ArmorStandEntityBundle

§

impl Bundle for ArrowEntityBundle

§

impl Bundle for AxolotlEntityBundle

§

impl Bundle for BatEntityBundle

§

impl Bundle for BeeEntityBundle

§

impl Bundle for BlazeEntityBundle

§

impl Bundle for BlockDisplayEntityBundle

§

impl Bundle for BoatEntityBundle

§

impl Bundle for CamelEntityBundle

§

impl Bundle for CatEntityBundle

§

impl Bundle for CaveSpiderEntityBundle

§

impl Bundle for ChestBoatEntityBundle

§

impl Bundle for ChestMinecartEntityBundle

§

impl Bundle for ChickenEntityBundle

§

impl Bundle for CodEntityBundle

§

impl Bundle for CommandBlockMinecartEntityBundle

§

impl Bundle for CowEntityBundle

§

impl Bundle for CreeperEntityBundle

§

impl Bundle for DolphinEntityBundle

§

impl Bundle for DonkeyEntityBundle

§

impl Bundle for DragonFireballEntityBundle

§

impl Bundle for DrownedEntityBundle

§

impl Bundle for EggEntityBundle

§

impl Bundle for ElderGuardianEntityBundle

§

impl Bundle for EndCrystalEntityBundle

§

impl Bundle for EnderDragonEntityBundle

§

impl Bundle for EnderPearlEntityBundle

§

impl Bundle for EndermanEntityBundle

§

impl Bundle for EndermiteEntityBundle

§

impl Bundle for EvokerEntityBundle

§

impl Bundle for EvokerFangsEntityBundle

§

impl Bundle for ExperienceBottleEntityBundle

§

impl Bundle for ExperienceOrbEntityBundle

§

impl Bundle for EyeOfEnderEntityBundle

§

impl Bundle for FallingBlockEntityBundle

§

impl Bundle for FireballEntityBundle

§

impl Bundle for FireworkRocketEntityBundle

§

impl Bundle for FishingBobberEntityBundle

§

impl Bundle for FoxEntityBundle

§

impl Bundle for FrogEntityBundle

§

impl Bundle for FurnaceMinecartEntityBundle

§

impl Bundle for GhastEntityBundle

§

impl Bundle for GiantEntityBundle

§

impl Bundle for GlowItemFrameEntityBundle

§

impl Bundle for GlowSquidEntityBundle

§

impl Bundle for GoatEntityBundle

§

impl Bundle for GuardianEntityBundle

§

impl Bundle for HoglinEntityBundle

§

impl Bundle for HopperMinecartEntityBundle

§

impl Bundle for HorseEntityBundle

§

impl Bundle for HuskEntityBundle

§

impl Bundle for IllusionerEntityBundle

§

impl Bundle for InteractionEntityBundle

§

impl Bundle for IronGolemEntityBundle

§

impl Bundle for ItemEntityBundle

§

impl Bundle for ItemDisplayEntityBundle

§

impl Bundle for ItemFrameEntityBundle

§

impl Bundle for LeashKnotEntityBundle

§

impl Bundle for LightningEntityBundle

§

impl Bundle for LlamaEntityBundle

§

impl Bundle for LlamaSpitEntityBundle

§

impl Bundle for MagmaCubeEntityBundle

§

impl Bundle for MarkerEntityBundle

§

impl Bundle for MinecartEntityBundle

§

impl Bundle for MooshroomEntityBundle

§

impl Bundle for MuleEntityBundle

§

impl Bundle for OcelotEntityBundle

§

impl Bundle for PaintingEntityBundle

§

impl Bundle for PandaEntityBundle

§

impl Bundle for ParrotEntityBundle

§

impl Bundle for PhantomEntityBundle

§

impl Bundle for PigEntityBundle

§

impl Bundle for PiglinEntityBundle

§

impl Bundle for PiglinBruteEntityBundle

§

impl Bundle for PillagerEntityBundle

§

impl Bundle for PlayerEntityBundle

§

impl Bundle for PolarBearEntityBundle

§

impl Bundle for PotionEntityBundle

§

impl Bundle for PufferfishEntityBundle

§

impl Bundle for RabbitEntityBundle

§

impl Bundle for RavagerEntityBundle

§

impl Bundle for SalmonEntityBundle

§

impl Bundle for SheepEntityBundle

§

impl Bundle for ShulkerEntityBundle

§

impl Bundle for ShulkerBulletEntityBundle

§

impl Bundle for SilverfishEntityBundle

§

impl Bundle for SkeletonEntityBundle

§

impl Bundle for SkeletonHorseEntityBundle

§

impl Bundle for SlimeEntityBundle

§

impl Bundle for SmallFireballEntityBundle

§

impl Bundle for SnifferEntityBundle

§

impl Bundle for SnowGolemEntityBundle

§

impl Bundle for SnowballEntityBundle

§

impl Bundle for SpawnerMinecartEntityBundle

§

impl Bundle for SpectralArrowEntityBundle

§

impl Bundle for SpiderEntityBundle

§

impl Bundle for SquidEntityBundle

§

impl Bundle for StrayEntityBundle

§

impl Bundle for StriderEntityBundle

§

impl Bundle for TadpoleEntityBundle

§

impl Bundle for TextDisplayEntityBundle

§

impl Bundle for TntEntityBundle

§

impl Bundle for TntMinecartEntityBundle

§

impl Bundle for TraderLlamaEntityBundle

§

impl Bundle for TridentEntityBundle

§

impl Bundle for TropicalFishEntityBundle

§

impl Bundle for TurtleEntityBundle

§

impl Bundle for VexEntityBundle

§

impl Bundle for VillagerEntityBundle

§

impl Bundle for VindicatorEntityBundle

§

impl Bundle for WanderingTraderEntityBundle

§

impl Bundle for WardenEntityBundle

§

impl Bundle for WitchEntityBundle

§

impl Bundle for WitherEntityBundle

§

impl Bundle for WitherSkeletonEntityBundle

§

impl Bundle for WitherSkullEntityBundle

§

impl Bundle for WolfEntityBundle

§

impl Bundle for ZoglinEntityBundle

§

impl Bundle for ZombieEntityBundle

§

impl Bundle for ZombieHorseEntityBundle

§

impl Bundle for ZombieVillagerEntityBundle

§

impl Bundle for ZombifiedPiglinEntityBundle

source§

impl Bundle for AdvancementBundle

source§

impl Bundle for LayerBundle

§

impl<C> Bundle for C
where C: Component,