From 03e0a9f23e6556d2c3821a9536f7e0795470bcec Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Sat, 6 Mar 2021 01:57:03 +0000 Subject: [PATCH] Docs for Bundle showing how to nest bundles (#1570) 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 Co-authored-by: Renato Caldas --- crates/bevy_ecs/src/bundle.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 71c222a377..e6b1012b4c 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -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.