- Create entities
- Find entities with specific components
Defining a Search
Start by defining the search, this is done in your system state struct. By convention, we put searches in thesystem/shared.go file.
system/shared.go
Using a Search
Creating Entities
We have a specific page on creating entities.Iterating Over Entities
You can use thePlayerSearch to search for entities with the PlayerTag and Position components.
system/example_player_system.go
Match Types
| Match Type | Description |
|---|---|
ecs.Contains | Entity must have at least these components |
ecs.Exact | Entity must have exactly these components |
ecs.Contains
Returns entities that contain at least the specified components (they may have additional components):
system/example_contains.go
- Entity with
[PlayerTag, Position, Health]→ ✅ Match - Entity with
[PlayerTag, Position]→ ✅ Match - Entity with
[PlayerTag]→ ❌ No match
ecs.Exact
Returns entities that contain exactly the specified components (no more, no less):
system/example_exact.go
- Entity with
[PlayerTag, Position, Health]→ ❌ No match - Entity with
[PlayerTag, Position]→ ✅ Match - Entity with
[PlayerTag]→ ❌ No match
ECS Concept: These match types reflect Entity Component System (ECS) patterns.
ecs.Contains
is useful for finding entities by their capabilities, while ecs.Exact is useful for finding
entities with a specific component combination.