In designing an entity-component system for my engine, I've come across a little snag in the way of storing and retrieving a particular type of component.
First, let me set clear up a bit of terminology I'm going to use in this question:
- I call "Component" a data structure that stores relevant data for a particular system.
- I call "System" an aggregation of methods and data structures that makes use of Components to update game state/interface with the user.
- An "Entity" is basically just an ID used to retrieve specific components and modify their data in game logic.
Each system owns an (ID-mapped) array of its type of Component (E.g Physics->PhysicsComponent, AI->AIComponent, Rendering->RenderingComponent), so that it can iterate efficiently over data.
Not all components are specifically owned by a system, however. For example, a Transform component stores an object's position, rotation and scale. It's one of the most important parts of an entity (Unity makes it mandatory, even), since it is used by a lot of systems, e.g. Physics, AI, Rendering etc.
This is pretty much the problem I'm facing. Since Transform is used by a lot of other systems, how should I go about retrieving one to use for each Component? One possible solution I see is to make each Component store its own Entity ID. It would be easy to retrieve any component like this, but it wouldn't be that efficient, and it also would go against the concept of a Component as an isolated and independent bundle of data, that isn't aware of any other.
Is there a proper way to solve this problem? Should Transform even be a component?