Tags are components without data. They are used to mark or categorize entities without storing any associated values. Think of them as boolean flags that can be added or removed from entities.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ukendio/jecs/llms.txt
Use this file to discover all available pages before exploring further.
Why Use Tags?
A tag takes zero bytes of storage per entity. More importantly, tags enable a different mental model. When you see a tag on an entity, you know it’s just a marker and there’s no data to read or write. Tags are entities that do not have the builtinjecs.Component trait, which tells the ECS that this ID cannot store any data—it is just a marker.
Creating Tags
There are two ways to create tags:1. Using jecs.tag() (Recommended)
Preregister a tag entity that will be allocated when you create the world:
This is the “proper” way to create tags. It ensures a stable type ID by registering the tag before creating the world. See the guide on preregistering components for more details.
2. Using world:entity()
Create a regular entity ID and use it as a tag:
Adding Tags
Useworld:add() to add a tag to an entity:
Checking for Tags
Useworld:has() to check if an entity has a tag:
jecs.is_tag():
Removing Tags
Useworld:remove() to remove a tag from an entity:
Tags vs Components
| Feature | Tags | Components |
|---|---|---|
| Storage | 0 bytes per entity | Type-specific bytes per entity |
| Adding | world:add() | world:set() |
| Reading | world:has() | world:get() |
| Removing | world:remove() | world:remove() |
| Use case | Marking/categorizing | Storing data |
Example Use Cases
Tags are perfect for:- State flags:
Dead,Alive,Stunned,Frozen - Categories:
Npc,Player,Enemy,Ally - Capabilities:
CanFly,CanSwim,CanTeleport - Temporary markers:
Dirty,Updated,Scheduled
Tags can be used in queries just like components. Use
query:with() to filter for entities that have a tag without retrieving any data.