Bundle is something similar to class in OOP for our Entity. It helps you create easily an entity with set of Components.
Bundle as a struct
- To create a bundle, pass the trait
Bundle
before your struct:
- Then, you can spawn the bundle in setup system:
- If you want to create an entity with default value, u can derive the Default trait for it:
- You can then spawn Player like this:
Common mistake
- U might think that you can query components by using bundle. But that is wrong. You should always do
Query<(&Component1, &Component2, ...), With<Marker>)
instead.