2222
2323EntitiesDb is built around a classic data-oriented ECS design:
2424
25- ### ** Entities**
26-
27- Lightweight integer IDs. They have no data themselves — components define the data.
28-
29- ### ** Components**
30-
31- Plain C# types (` struct ` , ` class ` , ` record ` , etc). Stored densely in chunked arrays.
32-
33- ### ** Archetypes**
34-
35- Unique sets of components. Entities with the same component signature are grouped into the same chunk layout.
36-
37- ### ** Queries**
38-
39- Pull in chunks of entities matching component filters — the basis for all system updates.
40-
41- ### ** Source-Generated Iterators**
42-
43- ` ForEach ` methods generate strongly-typed, allocation-free iteration code.
25+ * ** Entities** : Lightweight integer IDs. They have no data themselves — components define the data.
26+ * ** Components** : Plain C# types (` struct ` , ` class ` , ` record ` , etc). Stored densely in chunked arrays.
27+ * ** Archetypes** : Unique sets of components. Entities with the same component signature are grouped into the same chunk layout.
28+ * ** Queries** : Pull in chunks of entities matching component filters — the basis for all system updates.
29+ * ** Source-Generated Iterators** : ` ForEach ` methods generate strongly-typed, allocation-free iteration code.
4430
4531---
4632
@@ -58,17 +44,17 @@ var options = new EntityDatabaseOptions(
5844var db = new EntityDatabase (options );
5945```
6046
61- Each database is completely isolated, allowing multiple worlds.
62-
6347---
6448
6549# Entities
6650
6751``` csharp
52+ // create entity
6853var entity = db .Create (new Position (10 , 10 ), new Health (100 , 100 ));
69-
7054db .Exists (entity ); // true
71- db .Destroy (entity .Id ); // destroy
55+
56+ // destroy entity
57+ db .Destroy (entity ); // destroy
7258db .Exists (entity ); // false
7359```
7460
@@ -79,26 +65,27 @@ db.Exists(entity); // false
7965
8066# Components
8167
82- Components are simple data types:
68+ Components are simple data types that can be ` struct ` or ` class ` :
8369
8470``` csharp
8571public record struct Position (float X , float Y );
8672public record struct Velocity (float Dx , float Dy );
8773```
74+ > * ` class ` components should be avoided when fast enumeration is a priority of the component*
8875
8976### Add / Read / Write / Remove
9077
9178``` csharp
92- db .Add (entity . Id , new Velocity (10 , 10 ));
79+ db .Add (entity , new Velocity (10 , 10 ));
9380
94- db .Has <Velocity >(entity . Id ); // true
81+ db .Has <Velocity >(entity ); // true
9582
96- db .Set (entity . Id , new Velocity (200 , 200 )); // overwrite component
83+ db .Set (entity , new Velocity (200 , 200 )); // overwrite component
9784
98- db .Remove <Velocity >(entity . Id );
85+ db .Remove <Velocity >(entity );
9986
10087// Read-only
101- readonly ref var position = ref db .Read <Position >(entity . Id );
88+ ref readonly var position = ref db .Read <Position >(entity );
10289
10390// Write
10491ref var pos = ref db .Write <Position >(entity .Id );
@@ -113,7 +100,7 @@ Buffers act like **inline component lists**, stored directly in the chunk.
113100Only ` unmanaged ` types can be buffered.
114101
115102``` csharp
116- [Buffer (8 )]
103+ [Buffer (8 )] // use the buffer attribute to mark a component as buffered and passing the inline buffer size
117104public record struct InventoryItem (int Id , int Count );
118105```
119106
@@ -126,7 +113,7 @@ var entity = db.Create(
126113 new [] {
127114 new InventoryItem (1 , 1 ),
128115 new InventoryItem (2 , 10 )
129- } // Buffer must be the last argument
116+ } // Buffers must be the last component arguments
130117 );
131118```
132119
@@ -149,7 +136,7 @@ write.Add(new InventoryItem(3, 5));
149136
150137## Tags
151138
152- Tags are ** zero-data components** used for classification:
139+ Tags are ** zero-data components** used for classification and filtering :
153140
154141``` csharp
155142[Tag ] public struct PlayerTag { }
@@ -241,12 +228,18 @@ query.ForEachChunk((int len,
241228
242229# Change Filter
243230
231+ Enable change filtering with the ` TrackChanges ` attribute:
232+ ``` csharp
233+ [TrackChanges ]
234+ public record struct Position (float X , float Y );
235+ ```
236+
244237Only enumerate chunks whose components were written recently.
245238
246239``` csharp
247240var query = db .QueryBuilder
248241 .WithAll <Position , SentPosition , PositionDelta >()
249- .WithChangeFilter <Position >()
242+ .WithChangeFilter <Position >() // add change filter
250243 .Build ();
251244
252245query .ForEach ((in Position pos , ref SentPosition sent , ref PositionDelta delta ) =>
0 commit comments