top of page

Entity component system - space shooter

Stay tuned for my graduation project. An optimized space shooter using Entity Component Systems, an almost forgotten technique to achieve a large amount of entities while keeping optimization performant.

ECS stands for Entity Component System, and it's a data-oriented design pattern used in game development, especially popular in frameworks like Unity DOTS (Data-Oriented Technology Stack). An almost forgotten technique, this is used to create a large amount of game entities while keeping performance high.

E

Entities- These are unique identifiers that serve as placeholders or containers for components.

Components- These are data structures that contain specific attributes or properties that are placed inside entities.

C

Systems- These contain the logic that operates on entities possessing specific components.

S

image.png
image.png

It's something that would be overkill in let's say a simple platformer but a great tool on projects that necessitates a large amount of entities such as a space shooter. 

image.png

2.Why did I choose ECS?

I chose to work with ECS because I wanted to take on something I never worked with before. It has a steeper learning curve, a developer accustomed to object-oriented programming (OOP) such as me found that ECS concepts challenging to grasp initially. Understanding how to decompose entities into components and systems requires a shift in thinking from traditional OOP paradigms. A new complication to take on where I could challenge myself and flip the script on everything I have learned so far. I would push myself into an uncomfortable position in order to grow as a programmer.

3.Working with ECS- obstacles and difficulties

My plan was simple, create one entity, multiple it by 1000 and spread them around my canvas, give them visuals and physics and in the end- create a ship to shoot them all down. 

So I started by downloading the packages. Unlike game objects, an entity is empty, nothing. So I have to create create a script where I would store all the components I needed, a position component and a speed component so I can move them around, then I used gizmos to visualize them for now. Using a "forloop" and an "entitiescount" I instantiate 100 entities.

And now, it's time to make them seen...​

My first and biggest issue, which plagued me throughout the entire project, was the mismatch between the release numbers of Unity and the ECS packages required for Unity DOTS to work, causing incompatibilities between them.

image.png
image.png
image.png

SharedComponentData, SharedData, RenderMesh, SharedRenderMesh, Managed, Unmanaged... I could not get the mesh rendering to work and visualize my entities. I tried baking, referencing, super old versions but nothing would work and i would step way out of my circle of knowledge, syntaxes and structures I have never hear of before.

So, I decided to approach it differently. My solution? TMPro. My enemies will simply be

"0"s and "1"s. This workaround saved me hours of frustration and avoided the rabbit hole

of chasing down compatible packages or waiting for updates. Sure, it comes with a slight

performance hit, since TMPro relies on GameObjects,

but going hybrid felt like the sanest choice.

I created a collider, placed the TMPro inside, turned it into a prefab, and referenced it as a

component on my entity. This way, the text is bound directly to the entity's position via the

prefab itself. Instantiating the text as a separate prefab from the spawner would have required

constantly syncing its position with the entity and collider—adding unnecessary overhead.

With this setup, I was able to move forward and even built a simple ship that spawns bullets.

Desktop 2025.03.19 - 13.13.04.03.DVR - Trim (online-video-cutter.com).gif
Desktop 2025.03.19 - 13.12.43.02.DVR - Trim (online-video-cutter.com).gif

(WORK IN PROGRESS)

bottom of page