|
2 | 2 | //!
|
3 | 3 | //! This module contains the [`Bundle`] trait and some other helper types.
|
4 | 4 |
|
| 5 | +/// Derive the [`Bundle`] trait |
| 6 | +/// |
| 7 | +/// You can apply this derive macro to structs that are |
| 8 | +/// composed of [`Component`]s or |
| 9 | +/// other [`Bundle`]s. |
| 10 | +/// |
| 11 | +/// ## Attributes |
| 12 | +/// |
| 13 | +/// Sometimes parts of the Bundle should not be inserted. |
| 14 | +/// Those can be marked with `#[bundle(ignore)]`, and they will be skipped. |
| 15 | +/// In that case, the field needs to implement [`Default`] unless you also ignore |
| 16 | +/// the [`BundleFromComponents`] implementation. |
| 17 | +/// |
| 18 | +/// ```rust |
| 19 | +/// # use bevy_ecs::prelude::{Component, Bundle}; |
| 20 | +/// # #[derive(Component)] |
| 21 | +/// # struct Hitpoint; |
| 22 | +/// # |
| 23 | +/// #[derive(Bundle)] |
| 24 | +/// struct HitpointMarker { |
| 25 | +/// hitpoints: Hitpoint, |
| 26 | +/// |
| 27 | +/// #[bundle(ignore)] |
| 28 | +/// creator: Option<String> |
| 29 | +/// } |
| 30 | +/// ``` |
| 31 | +/// |
| 32 | +/// Some fields may be bundles that do not implement |
| 33 | +/// [`BundleFromComponents`]. In those cases you can either ignore it as above, |
| 34 | +/// or you can opt out the whole Struct by marking it as ignored with |
| 35 | +/// `#[bundle(ignore_from_components)]`. |
| 36 | +/// |
| 37 | +/// ```rust |
| 38 | +/// # use bevy_ecs::prelude::{Component, Bundle, ChildOf, Spawn}; |
| 39 | +/// # #[derive(Component)] |
| 40 | +/// # struct Hitpoint; |
| 41 | +/// # #[derive(Component)] |
| 42 | +/// # struct Marker; |
| 43 | +/// # |
| 44 | +/// use bevy_ecs::spawn::SpawnRelatedBundle; |
| 45 | +/// |
| 46 | +/// #[derive(Bundle)] |
| 47 | +/// #[bundle(ignore_from_components)] |
| 48 | +/// struct HitpointMarker { |
| 49 | +/// hitpoints: Hitpoint, |
| 50 | +/// related_spawner: SpawnRelatedBundle<ChildOf, Spawn<Marker>>, |
| 51 | +/// } |
| 52 | +/// ``` |
5 | 53 | pub use bevy_ecs_macros::Bundle;
|
6 | 54 |
|
7 | 55 | use crate::{
|
|
0 commit comments