Hey Bas and Coen, thank you for your answers!
I agree that dependency is maybe not the right term for it, I was just wondering if there is some general way to ensure that components of a certain type are always initialised before components of another type, without enforcing that there has to be at least one component of this type.
Just to make sure I understand it completely, are the following two statements correct?:
- If you have a component A that depends on components of type B (of which there could be zero, one or more), the only real way to ensure that all components of type B are initialised before component A initialises is to create a vector<ComponentPtr> property in A in which you add every component of type B in Napkin.
- However, if you know there will always be at least one component of type B, you can use the getDependentComponents() method in C++.
If so, wouldn’t it make sense to be able to achieve the first situation in C++ as well? (for example by having an ‘optional’ flag when adding a component to the getDependentComponents list, which would just carry on initialisation if no component is there instead of failing)
(not necessarily advocating this, just trying to understand the logic behind the system )
I guess another way to make component A aware of all components of type B is to make type B depend on type A and make components of type B register at component A during their initialisation (so after initialisation of component A). But the downside of this solution is that component A won’t be able to execute an action after all components of type B are registered, because it can never know if a component registering is the last one.
Is there another way to set this up that I’m missing?