Down the ECS Rabbit Hole


In my last log I mentioned that I get bored of projects really easily. My computer is literally a graveyard of probably 15 or so prototypes in various forms of completion (maybe 75% of which are platformers) that don't get any love. Many of which include a different design pattern from the rest, in keeping with my tradition of "try all the design patterns!" Well, I had told myself I wasn't going to go down that road again but after seeing a GDC talk about ECS I was itching with intrigue and just HAD to try to implement it.

Since this is a [Unity](https://unity3d.com) project (eagle-eyed readers may have noticed that the first prototype video I shared was SpriteKit tho!), when it comes to ECS the current go-to framework is Entitas-CSharp which is a ECS framework made specifically for C# / Unity by some of the guys at Wooga. It's some really interesting tech, that said after doing some tests and playing around with it I decided that it just wasn't for me. It felt too detached from the normal Unity workflow and I didn't like how certain things were handled as well as the fact that it mostly depends on generated code; it just felt like too much was out of my hands and controlled by some black box.

I spent the next few weeks playing around with writing my own ECS framework with varying levels in intricacy; but after about 4 different versions I decided to settle on an extremely simplified version of the pattern that could potentially be considered an ECS/MVC pattern. It enforces the separation of data / logic but maintains the standard Unity workflow and keeps how things are working very transparent for easy debugging.

While this took some time away from working on developing the game itself, this allows for quick addition of new features, easy debugging of functionality ("oh, the thrust is acting up? let me pop into the thrust system and see what is going on"), performance benefits due to limiting each GameObject to only one MonoBehaviour, and the standard Unity workflow of throwing GameObjects into a scene and being able to tweak everything needed in there with no issues. Since I am currently not dealing with any entity managers, implementation/scaffolding was very trivial as well since it just required writing base classes for Entities, Components, and Systems. It's already increased my productivity a lot; that said, I will likely tweak this in the future to contain an Entity manager so there will only be a single instance of any given System acting on entities based on a component identifier that will determine whether or not the system cares about a specific entity, but I'll leave that for another day.

You can see a more in-depth version of this post along with code samples over at my blog.

Leave a comment

Log in with itch.io to leave a comment.