2025-02-19 16:10:38 +00:00
# Jecs API Reference
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
Jecs provides a simple but powerful API for entity component systems. This page documents the core API.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
## Core Types
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### World
2024-09-07 20:12:07 +00:00
```luau
jecs.World: World
```
2025-02-19 16:10:38 +00:00
The main container for all ECS data. See [World API ](world.md ) for details.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### Entity
2024-09-07 20:12:07 +00:00
```luau
2025-02-19 16:10:38 +00:00
type Entity< T = unknown >
2024-09-07 20:12:07 +00:00
```
2025-02-19 16:10:38 +00:00
A unique identifier that can have components attached. The generic type `T` represents the data type of the entity when used as a component.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### Id
2024-09-07 20:12:07 +00:00
```luau
2025-02-19 16:10:38 +00:00
type Id< T >
2024-09-07 20:12:07 +00:00
```
2025-02-19 16:10:38 +00:00
Represents either an Entity or a Pair that can be used to store component data of type `T` .
## Core Functions
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### pair()
2024-09-07 20:12:07 +00:00
```luau
2025-02-19 16:10:38 +00:00
function jecs.pair(
first: Entity, -- The first element of the pair (relationship)
object: Entity -- The second element of the pair (target)
): number -- Returns the ID representing this relationship pair
2024-09-07 20:12:07 +00:00
```
2025-02-19 16:10:38 +00:00
Creates a relationship pair between two entities. Used for creating relationships like parent-child, ownership, etc.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
::: info
Note that while relationship pairs can be used as components (meaning you can add data with them as an ID), they cannot be used as entities. You cannot add components to a pair as the source of a binding.
:::
Example:
```lua
local ChildOf = world:component()
local parent = world:entity()
local child = world:entity()
-- Create parent-child relationship
world:add(child, pair(ChildOf, parent))
2024-09-07 20:12:07 +00:00
```
2025-02-19 16:10:38 +00:00
## Constants
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### Wildcard
2024-09-07 20:12:07 +00:00
```luau
2025-02-19 16:10:38 +00:00
jecs.Wildcard: Entity
```
Special entity used for querying any entity in a relationship. See [Relationships ](../learn/concepts/relationships.md ).
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### Component
```luau
jecs.Component: Entity
2024-09-07 20:12:07 +00:00
```
2025-02-19 16:10:38 +00:00
Built-in component type. Every component created with `world:component()` has this added to it.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### ChildOf
```luau
jecs.ChildOf: Entity
```
Built-in relationship type for parent-child hierarchies.
2024-09-07 20:12:07 +00:00
2025-02-19 16:10:38 +00:00
### Rest
```luau
jecs.Rest: Entity
```
Special component used in queries to match remaining components.