Entity structure made simple

You don't need a complex ECS. It'll slow you down. Do this instead.

words I like:

Solve real problems that come from code you have written.
Not imaginary problems in code you are yet to write.
Type out the simplest version first.

This one thing I'm about to share has increased my speed of game development a shit load.

I've been using & tweaking what I'm about to show you for around 4 years across many different projects.

The best part, it takes no time at all to set up and start using straight away.

That way you've got one less thing to think about when trying to write a game from scratch, increasing your odds of actually finishing something.

I've written the rest of this inside a code example so it's easier to communicate. But here's a rough overview:

  • You don't need a complicated entity system, use a single data structure for everything

  • Zero by default, opt in to behaviour by setting certain state

  • Use handles for "pointing" to other entities

  • Try keep data & code local to the entity setup function

I got this idea from a mentor of mine back in the day (Ryan Fleury), and I’ve been using it ever since. 10/10 would megastruct again.

common hangups:

Isn't that messy?
-> yes. But the CPU doesn't care. If you really want to make it "clean" you can use comments to segment things.

Isn't it a waste of memory?
-> yes, but you would be surprised how little this matters.

How can I make this more memory efficient?
-> give up and become a monk living in the mountains

For real though?
-> If you reaaallly need it, and have observed an actual issue in your game that is effecting the user experience, and there's no way around it... That's when you take the next step and add more complexity.

You can look into doing a discriminated union with a simple shared base entity structure.

One part of the complexity here is now you have to think about where data should go. This is ultimately why I've found ECS's to be pretty useless in practice. I spend more time thinking about how I should neatly organise my data structures and what should go where, rather than doing the work that actually matters (adding more content and writing more gameplay code).

If it ain't broke, don't fix it.

tl;dr

Simplify your entity structure, and you simplify your ability to write and iterate on gameplay code. Which means making better games faster.

Do the simple thing first. Only adjust when you encounter real problems. Then solve for those in a direct way. Don't solve imaginary problems you think you might have.

I hope you've now got one less thing to think about.

Chuck us a reply if you've got any questions.