Skip to content

Commit

Permalink
Docs for Bundle showing how to nest bundles (bevyengine#1570)
Browse files Browse the repository at this point in the history
I've also added a clearer description of what bundles are used for, and explained that you can't query for bundles (a very common beginner confusion).

Co-authored-by: MinerSebas <[email protected]>
Co-authored-by: Renato Caldas <[email protected]>
  • Loading branch information
3 people committed Mar 6, 2021
1 parent 0068483 commit 03e0a9f
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,32 @@ use crate::{
use bevy_ecs_macros::all_tuples;
use std::{any::TypeId, collections::HashMap};

/// An ordered collection of components
/// An ordered collection of components, commonly used for spawning entities, and adding and removing components in bulk.
///
/// See [Bundle]
/// You cannot query for a bundle, only individual components within it.
///
/// Typically, you will simply use `#[derive(Bundle)]` when creating your own `Bundle`.
/// The `Bundle` trait is automatically implemented for tuples of components:
/// `(ComponentA, ComponentB)` is a very convenient shorthand when working with one-off collections of components.
/// Note that both `()` and `(ComponentA, )` are valid tuples.
///
/// You can nest bundles like so:
/// ```
/// # use bevy_ecs::bundle::Bundle;
///
/// #[derive(Bundle)]
/// struct A {
/// x: i32,
/// y: u64,
/// }
///
/// #[derive(Bundle)]
/// struct B {
/// #[bundle]
/// a: A,
/// z: String,
/// }
/// ```
/// # Safety
/// [Bundle::type_info] must return the TypeInfo for each component type in the bundle, in the _exact_
/// order that [Bundle::get_components] is called.
Expand Down

0 comments on commit 03e0a9f

Please sign in to comment.