# Entity Component System data duplicate

I've read some articles about Entity Component System and I like this idea of "entities" having lots of "components" to define them, so I tried to implement it. Here is an simple overview of what i've got so far:

I've a template class that will hold a list for each component type that exit

That allows me to have a collection of components by its type

Which is good because in memory components will be contiguous

Then I've a component manager that hold all these collections and allows me to retrieve a collection at any time

Also, each entity keeps tack of all components it has with a bitset

So in the final result, each index of all component containers belongs to an entity

I know that this causes a problem than, not all entities have all components, so it causes a waste of space... But for now, I can (saldy) live with it

But the real issue for me here is that some components will have same data, and if each entity have a component for that data, this data will be duplicated unnecessary

Even worst, it would require OpenGL to have different objects in memory that are exactly equal and having to enable those objects and disable them many times is not desirable at all.

I've been scratching my head to figure out a solution for this issue but I can't find any. Could someone give me an advice please?

If you've read this far, Thank You!

• Pointer to the data, or have a class that wraps the VBO, and only gives a reference to it for each element. Note you don't need to use entity component systems for every element of your game, and if your entity component system is making it more difficult to make your project you're doing it wrong, or it doesn't belong in your project. Feb 2 '18 at 14:27
• Entity Component System solves a lot of problems and most of articles about this pattern/principle show some basic implementation giving the idea that it is easy to implement, so I decided to try it out, but it seems that it is not that trivial as "they" say. Feb 2 '18 at 14:49
• Entity component systems solve one specific problem that spawns a lot of issues, they do not solve a lot of problems. ECS is meant to solve adding uncapped number of effects, features, aspects, etc.. to "entities" in your game with out having to make entity classes specific to each of those combinations of components. If you have a very large or wide hard to maintain class hierarchy, and the number of entities isn't the largest performance cost, ECS system is a potential solution. It is not a general tool for every game. In RPGs it can make sense, but in counter strike or starcraft? No. Feb 2 '18 at 14:58

When you have a large amount of data shared between multiple game entities, then the component representing that data might be a good candidate for the flyweight pattern. Your Mesh component shouldn't include the full mesh data. It should only have a reference to which mesh asset is used to represent that entity (in an OpenGL-based graphic engine, this could just be the ID of the vertex buffer object), plus any entity-specific metadata which is relevant to how that mesh is applied to this particular entity. The mesh assets themselves should be stored in an own data structure separated from the entities.