1
\$\begingroup\$

I've just started to try and learn how to use ECS (Entity component systems), but I'm having trouble understanding the concepts behind components.

Should adding more types of components, or trying to make a component reusable through its fields be favored? For example, if I'm trying to give all entities a shape for collision detection, should I have a different component for every shape (RectangleComponent, CircleComponent, PolygonComponent), or should I have one ShapeComponent, and in there have a field which is of type Shape, with class Shape having subclasses Rectangle, Circle, and Polygon.

I'm unsure because using a Shape seems to be much more flexible and easier to implement systems, but it also feels like I'm violating the ECS rule of not having any functionality in components.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

feels like I'm violating the ECS rule

There is no ECS police that will come and put you in ECS Jail. This is your architecture, you set it up how it fits your needs.

having any functionality in components.

I don't see any functionality in what you suggest. I only see data.

At their core, all of those are effectively shapes and will have to be treated more or less all in the same fashion when they'll go through your systems. If you set them up as different individual component types, you'll have a hard time deciding which of those shapes will be processed by the system first, then second, then third, etc., or you'll have a hard time to group them together to process them in a consistent fashion.

It's fine to have a ComponentShape, and have data about the shape in it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .