Hello!
I have a lot of free time and I want the project I'm working on to be as clean as possible, even though it means a lot more work for me. I've started creating those cards that show the rough component structure for the game elements:

Here is one for a NPC character (all the components are children of the Mouse scene). Every mouse can work in one of the different workplaces. When employed, the work component will be changed accordingly to match the work type. And as you can see some of the components require others (like the detector component here). It's easy to set up the hunger component for example, because it's present in the scene from the beginning and I can just have an export variable pointing to the detector and set it in the editor. However it's another situation for the work component, because the base class doesn't require a reference to the detector and the inheriting components do.

My question is, how to correctly pass the reference to the detector when for example gatherer component is set?
The only option I see is getting it by its path, whether it's done by the gatherer component, or by the workplace or whatever else. Of course I know that it works, but it's not what I want. I want the perfect components that are fully independent from each other, but I don't know if that's even possible. This would be the only place where they lose independency from each other and it bugs me a lot.

I know it's probably a very stupid question, but if you know any way around it, please let me know. And please don't respond to just do it in whatever way works, it's not the point of my question.

  • xyz replied to this.

    cymus My question is, how to correctly pass the reference to the detector when for example gatherer component is set

    Mouse (the system) should manage the reference. It ought to make it known to the gatherer component as soon as it becomes available.

    Alternatively, redesign your system to not use "components" at all. It looks like it reached dangerous levels of overdesign 🙂

      xyz What do you suggest instead of it?

      • xyz replied to this.

        cymus Put all possible mouse functionality into the Mouse class and use as needed. Having modular standalone components only makes sense if they can be plugged into many various systems. If all of the shown components are supposed to be plugged only into the mouse system, then there's no benefit whatsoever in having them as separate classes.

        If detector is not a separate component then the gathering code doesn't need to worry about acquiring a reference to it 🙂