mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 20:53:53 +00:00
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 <scherthan_sebastian@web.de> Co-authored-by: Renato Caldas <renato@calgera.com>
This commit is contained in:
parent
006848311c
commit
03e0a9f23e
1 changed files with 25 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue