Skip to content

Latest commit

 

History

History
114 lines (77 loc) · 4.49 KB

File metadata and controls

114 lines (77 loc) · 4.49 KB

GECS

Entity Component System for Godot 4.x

Build scalable, maintainable games with clean separation of data and logic. GECS integrates seamlessly with Godot's node system while providing powerful query-based entity filtering.

✨ Key Features

  • 🎯 Godot Integration - Works with nodes, scenes, and editor
  • 🚀 High Performance - Optimized queries with automatic caching
  • 🔧 Flexible Queries - Find entities by components, relationships, or properties
  • 🔍 Debug Viewer - Real-time inspection and performance monitoring
  • 📦 Editor Support - Visual component editing and scene integration
  • 🎮 Battle Tested - Used in games being actively developed
# Create entities with components
var player1 = Entity.new()
player1.add_component(C_Health.new(100))
player1.add_component(C_Velocity.new(Vector2(5, 0)))

var player2 = Entity.new()
player2.add_component(C_Health.new(100))
player2.add_component(C_Velocity.new(Vector2(-5, 0)))

# Add entity to the world
ECS.world.add_entities([player1, player2])

# Add relationships to entities
# Player 1 is an Ally to Player 2
player1.add_relationship(Relationship.new(C_AllyTo.new(), player2))
# Player 2 is a little suspicious of Player 1
player2.add_relationship(Relationship.new(C_SuspiciousOf.new(), player1))

# Components define data only
class_name C_Velocity extends Component

@export var velocity := Vector3.ZERO


# Systems process entities with specific components
class_name VelocitySystem extends System

# Systems define queries to select entities and iterate their components
func query() -> QueryBuilder:
    return q.with_all([C_Velocity, C_Transform]).iterate([C_Velocity, C_Transform])

# Systems implement process to handle selected entities
func process(entities: Array[Entity], components: Array, delta: float) -> void:
    var c_velocities = components[0] # C_Velocity (first in iterate)
    var c_transforms = components[1] # C_Transform (second in iterate)

    # Process all velocity and transform components on entities that match query
    for i in entities.size():
        var c_velocity := c_velocities[i] as C_Velocity
        var c_transform := c_transforms[i] as C_Transform
        c_transform.transform.global_position += c_velocity.velocity * delta

# Add systems to the world
ECS.world.add_system(VelocitySystem.new())

# Progress the world and call all systems
ECS.world.process(delta)

⚡ Quick Start

  1. Install: Download to addons/gecs/ and enable in Project Settings
  2. Follow Guide: Get your first ECS project running in 5 minutes →
  3. Learn More: Understand core ECS concepts →

📚 Complete Documentation

All documentation is located in the addon folder:

Complete Documentation Index

Quick Navigation

Advanced Features

🎮 Example Games

🌟 Community

📄 License

MIT - See LICENSE for details.


GECS is provided as-is. If it breaks, you get to keep both pieces. 😄

Star History Chart