1
\$\begingroup\$

I'm developing a somewhat simple, small roguelike game as my university project. Early into development I heard about Enity-Component-System and decided to go with that as my game's architecture. Since this is my first ever project using that design, I ran into some problems that I'm not sure are a result of the principles or my own mistakes. As an example:

I have an inventory system, handling inventory operations of managing, using and dropping items. The problem I ran into is the fact, that in order to actually do something like using potions, I have to either include an instance of the Health System (which I now realize is technically just a bunch of glorified functions dealing with health) or copy all that code into the inventory system, which I don't find a good solution either.

How do I get over this? I don't know if my design is simply flawed, or if I'm trying to be too much of a purist. Any help/tips would be greatly appreciated

\$\endgroup\$
7
  • \$\begingroup\$ If the Health System is just "a bunch of glorified functions", can you just make it a static class that can be accessed from any other class? What language are you using? \$\endgroup\$
    – Kevin
    Commented Apr 7, 2023 at 0:20
  • \$\begingroup\$ You could potentially have a "consumer" system that acts against an inventory/item component and the consuming entity's health stats component. \$\endgroup\$
    – Basic
    Commented Apr 7, 2023 at 0:40
  • \$\begingroup\$ @Kevin I'm using C++, tbh I think that I might indeed do that, considering I've ran into this issue before with the AI system, which I resolved by just making the ai system have a reference to the health and positon system but I felt it wasn't a good solution \$\endgroup\$
    – aallfik11
    Commented Apr 7, 2023 at 9:17
  • \$\begingroup\$ I don't think "Inventory" should be a system in the ECS sense. Systems should correspond to data transformations, but there's no one particular signature for data transformations that all inventory items need - a healing potion doesn't modify data the same way a scroll of fireball does. One-off item usage might be a good use case for a message queue, issuing a "heal" message for your health system to incorporate on its update pass. \$\endgroup\$
    – DMGregory
    Commented Apr 7, 2023 at 17:53
  • \$\begingroup\$ @DMGregory After reading what you said, I realised my approach might not have been very good then. In what I'm building, I don't have any message systems in place and instead I rely on iterating through each entity and doing something for it depending on the AI/Player's action, with no update queue or anything like that. Sounds like a good idea, though, I'll probably utilize it next time I'll be building something, or maybe I'll refactor once I'm certain I have enough time left for that \$\endgroup\$
    – aallfik11
    Commented Apr 8, 2023 at 18:48

0

You must log in to answer this question.