
Fixing TypeScript Error: Subsequent Variable Declarations Must Have Same Type
The Debug Zone
Built From Scratch: 2D Game Engine โ Entity Component System Title: Entity Component System In this episode, we build a complete Entity Component System (ECS) from the ground up, giving our engine the architectural backbone it needs to scale. We create the @ges/ecs package with a World class that manages entities, components, and systems, then wire it into the core bundle. The ECS pattern separates data from behavior, making our game objects flexible, performant, and easy to reason about. Clean queries, composable systems, and a foundation built to handle hundreds of entities without breaking a sweat. ๐ Links Repo (main): https://github.com/CodingButter/GameE... Episode branch: https://github.com/CodingButter/GameE... Previous episode: https://www.youtube.com/watch?v=cFh5zKOjXSY ๐ก What You'll Learn What an Entity Component System is and why it's used in game engines How to design a World class that manages entities, components, and systems How to implement efficient component storage using Maps for fast lookups How to build a query system that finds entities matching specific component combinations How to separate update logic and render logic using system abstractions How to integrate ECS into your existing engine and core packages ๐งฐ Tech Stack Tool Role Bun Runtime + package manager for fast builds and workspaces Vite Instant feedback and React hot reload React Editor UI framework TypeScript Language for strong types and clear contracts Layout: apps/ for applications, packages/ for engine modules Core packages: @ges/core, @ges/engine, @ges/renderer, @ges/ecs โ๏ธ What We Built Created the @ges/ecs package with Entity, Component, and System types Implemented the World class with entity creation and component management Built a query system that efficiently filters entities by component types Added UpdateSystem and RenderSystem abstract classes for behavior Integrated ECS into the core package for unified access Prepared the architecture for real game objects and logic ๐ฏ Why It Matters ECS is the secret weapon behind modern game engines. By separating what things are (components) from what they do (systems), we get code that's easier to test, debug, and extend. Every future feature โ physics, collision, AI, networking โ will plug into this pattern without tangling up our codebase. ๐ฎ What's Next Build concrete component types like Transform, Velocity, and Sprite Create update systems for movement and physics Implement render systems that draw entities to the canvas Integrate the editor to visualize and debug entities in real time ๐ฌ Feedback I've been coding for 20 years, but I'm still learning. This series proves you don't need to be perfect to build something real โ you just need curiosity and persistence. If this helped, like, share, and subscribe, and drop your thoughts or improvements below. Chapters: 00:00 Intro & game plan 00:30 Last Episode Recap 01:00 What is ECS 03:30 Creating the ECS Package 05:45 Building the World Class 10:20 Component Registration & Storage 15:30 Query System Implementation 22:15 Update & Render Systems 26:40 Integration with Core 28:30 Recap