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)

  • \$\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\$ – Alexandre Vaillancourt May 1 '17 at 10:52
  • \$\begingroup\$ @AlexandreVaillancourt - Edited for clarity, I hope it helps! \$\endgroup\$ – Patrick May 1 '17 at 10:55

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.

  • \$\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 May 1 '17 at 16:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.