I’ve got an existing codebase for a game I made before I came across ECS. However, I did adopt some bits and pieces of ECS unwittingly.
---- Current System ----
I have a large StateTree, mostly just a collection of “Entity Containers,” basically Dictionary<Guid, T>. Each “entity” has a unique identifier (UUID). There are no methods/behaviours on these entities. There is no nesting of data, but unlike ECS, I do have properties on every entity. I have no distinction explicitly for a Component. I handle relationships via an “Engine” I wrote that handles storing lists of relationships by hash keys for fast lookup. I don’t have systems. I dispatch Events that get routed to the proper method that handles it (Technically, this is a redux style with reducers)
This has worked pretty well, I have done a lot of custom parallel code, and it’s fast, but I think with ECS, it could be much, much faster. I am struggling, though, when it comes to understanding an Entity vs. a Component when sometimes they seem to overlap for me. I’m not sure if it’s the vocabulary of how I’ve structured my game or what, but I’m hoping for some help “Thinking in ECS” :).
---- A quick case study example for my election simulation game. ----
I have Voters who have opinions on Candidates regarding Issues. So the way I have it structured now is Voters “own” VoterIssues, which “own” VoterIssueCandidates, which have approval ratings. When I say “own,” I mean an object type is indexed by something (A parent ID usually) for lookup. The player can run Ads on issues, which can sway a Voter’s Candidate Approval, for an Issue. We can run Polls to see how a candidate is performing in a state, broken down by the issues. Issues also own things like Topics, but trying to keep the example smaller!
I struggle to understand how to create hierarchical type content such as this in an ECS mindset. I would tend to say a Voter is an Entity, as is an Ad. Ads are owned by Actors (Player, Candidate). How do we represent this kind of hierarchal content in ECS? I’ve seen suggestions of a Relationship Component, though I’m not 100% on how that works.
Also, Ads have cost and reference an Issue, so is Issue an Entity or a component? Voters own VoterIssues which are containers for results for each candidate approval on an Issue… and it all kind of spins out to where I have no idea what my components are and what my entities are in this “simple” example, let alone how to connect them. It feels like the versatility of some of my usage of things like Issues makes it difficult to understand what is the nature of it in ECS.