Skip to content

Commit 03e0a9f

Browse files
alice-i-cecileMinerSebasrmsc
committed
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 <[email protected]> Co-authored-by: Renato Caldas <[email protected]>
1 parent 0068483 commit 03e0a9f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

crates/bevy_ecs/src/bundle.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,32 @@ use crate::{
88
use bevy_ecs_macros::all_tuples;
99
use std::{any::TypeId, collections::HashMap};
1010

11-
/// An ordered collection of components
11+
/// An ordered collection of components, commonly used for spawning entities, and adding and removing components in bulk.
1212
///
13-
/// See [Bundle]
13+
/// You cannot query for a bundle, only individual components within it.
14+
///
15+
/// Typically, you will simply use `#[derive(Bundle)]` when creating your own `Bundle`.
16+
/// The `Bundle` trait is automatically implemented for tuples of components:
17+
/// `(ComponentA, ComponentB)` is a very convenient shorthand when working with one-off collections of components.
18+
/// Note that both `()` and `(ComponentA, )` are valid tuples.
19+
///
20+
/// You can nest bundles like so:
21+
/// ```
22+
/// # use bevy_ecs::bundle::Bundle;
23+
///
24+
/// #[derive(Bundle)]
25+
/// struct A {
26+
/// x: i32,
27+
/// y: u64,
28+
/// }
29+
///
30+
/// #[derive(Bundle)]
31+
/// struct B {
32+
/// #[bundle]
33+
/// a: A,
34+
/// z: String,
35+
/// }
36+
/// ```
1437
/// # Safety
1538
/// [Bundle::type_info] must return the TypeInfo for each component type in the bundle, in the _exact_
1639
/// order that [Bundle::get_components] is called.

0 commit comments

Comments
 (0)