2
\$\begingroup\$

Reading up on ECS, I've tried to implement a simple 'game', if you can call it that. Basic concepts :

You have planets(entity), they produce gold. (gold is a component inside planet)
Planets can build buildings on themselves(Buildings component)
A building(entity) has associated gold costs(Costs component)

But costs component has Gold in it(or it needs to anyway)

As to my question :
Am I close with my interpretation of ECS(Should components be inside other components?)
Are resources a valid Component? if not, where would it make sense to place them?

Edit for clarity :

ECS - Entity-Component-System.
My entities are empty hash tables of components.
My components are used inside systems for game logic, the Treasury entity has a Gold component and the IncomeSystem updates that component.

Other components (Buildable, Population, Moveable)

\$\endgroup\$
2
  • \$\begingroup\$ When dealing with ECS, it's better to describe what E, C and S mean to you and your implementation, since there is no standard in what an ECS is. \$\endgroup\$
    – Vaillancourt
    Commented May 1, 2017 at 10:52
  • \$\begingroup\$ @AlexandreVaillancourt - Edited for clarity, I hope it helps! \$\endgroup\$
    – Patrick
    Commented May 1, 2017 at 10:55

1 Answer 1

3
\$\begingroup\$

First of all, there is no "right" or "wrong" way to structure a game's software architecture. Just ways which work or don't work for you.

Usually you wouldn't nest components. What you would do instead is nest entities by making them parents and children of each other.

  • The Universe entity has many Planet child-entities
  • A Planet entity has many Building child-entities

I am not sure if it makes sense to make Gold a full-fledged component. Is it really more than just a number? Does "gold" have any behavior or interaction with components of other entities? If not I would rather expect it to be a simple variable in the BuildCost-component, the ResourceProducer-component and the Treasury - component.

The only situation where you might have components with components is if you have some game feature which is so complex that you would implement it with a completely independent EC-System inside the component which hosts it.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thanks for your answer, I've been debating with myself whether or not Gold should be a Component, I think the reality is it shouldn't. \$\endgroup\$
    – Patrick
    Commented May 1, 2017 at 16:51

You must log in to answer this question.

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