This is a simple Entity Component System (ECS) implementation for Godot 4.3. The ECS architecture separates game objects (entities) from their data (components) and behavior (systems).
The World class manages all entities, components, and systems. It handles:
- Creating entities
- Adding components to entities
- Querying entities with specific component combinations
- Running systems each frame
A simple wrapper around an entity ID.
Base class for all components. Components should be data-only classes that inherit from this.
Base class for all systems. Systems operate on entities with specific combinations of components.
- Create component types by extending the Component class
- Create systems by extending the System class
- Create a World instance
- Add entities with components to the world
- Add systems to the world
# Create components
var position_comp = PositionComponent.new(Vector2(100, 100))
var sprite_comp = SpriteComponent.new("res://assets/character.png")
# Create entity and add components
var world = World.new()
var entity = world.create_entity()
world.add_component(entity, position_comp)
world.add_component(entity, sprite_comp)
# Add systems
world.add_system(MovementSystem.new())
world.add_system(RenderSystem.new())The systems will automatically process entities with the appropriate components each frame.