Skip to content

Commit 03601db

Browse files
Basic documentation for Entities, Components and Systems (#1578)
These are largely targeted at beginners, as `Entity`, `Component` and `System` are the most obvious terms to search when first getting introduced to Bevy.
1 parent 32af4b7 commit 03601db

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

crates/bevy_ecs/src/component/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ use std::{
1111
};
1212
use thiserror::Error;
1313

14+
/// A component is data associated with an `Entity`. Each entity can have multiple different types
15+
/// of components, but only one of them per type.
16+
///
17+
/// Any type that is `Send + Sync + 'static` automatically implements `Component`.
18+
///
19+
/// Components are added with new entities using [Commands::spawn](crate::system::Commands::spawn),
20+
/// or to existing entities with [Commands::insert](crate::system::Commands::insert),
21+
/// or their [World](crate::world::World) equivalents.
22+
///
23+
/// Components can be accessed in systems by using a [Query](crate::system::Query)
24+
/// as one of the arguments.
25+
///
26+
/// Components can be grouped together into a [Bundle](crate::bundle::Bundle).
1427
pub trait Component: Send + Sync + 'static {}
1528
impl<T: Send + Sync + 'static> Component for T {}
1629

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ use std::{
1313

1414
/// Lightweight unique ID of an entity
1515
///
16-
/// Obtained from `World::spawn`. Can be stored to refer to an entity in the future.
16+
/// Obtained from [World::spawn](crate::world::World::spawn), typically via [Commands::spawn](crate::system::Commands::spawn). Can be stored to refer to an entity in the future.
17+
///
18+
/// `Entity` can be a part of a query, e.g. `Query<(Entity, &MyComponent)>`.
19+
/// Components of a specific entity can be accessed using
20+
/// [Query::get](crate::system::Query::get) and related methods.
1721
#[derive(Clone, Copy, Hash, Eq, Ord, PartialEq, PartialOrd)]
1822
pub struct Entity {
1923
pub(crate) generation: u32,

crates/bevy_ecs/src/system/system.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ impl SystemId {
1717
}
1818

1919
/// An ECS system that can be added to a [Schedule](crate::schedule::Schedule)
20+
///
21+
/// Systems are functions with all arguments implementing [SystemParam].
22+
///
23+
/// Systems are added to an application using `AppBuilder::add_system(my_system.system())`
24+
/// or similar methods, and will generally run once per pass of the main loop.
25+
///
26+
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.
27+
/// It's possible to specify explicit execution order between specific systems,
28+
/// see [SystemDescriptor](crate::schedule::SystemDescriptor).
2029
pub trait System: Send + Sync + 'static {
2130
type In;
2231
type Out;

0 commit comments

Comments
 (0)