- A GameObject has Component1, which requires, say, a box collider trigger.
- ScriptA adds Component2 – which also requires a box collider trigger – to the GameObject.
- ScriptB adds Component3 – which also requires a box collider trigger – to the GameObject.
- Later, ScriptC Destroys Component3.
In an interest in tidiness, ScriptC should destroy Component3’s required box collider. B ut the box collider shares a codependency with Component1 and Component2.
I don’t see anything in the RequiredComponent documentation that points to how I might check whether any other components also require the box collider. (i.e. programmatic access to RequiredComponent attributes of components).
Any ideas on how to best solve this problem? Would I have to eliminate the RequireComponent attribute and programmatically add required components in Start(), and track them via that method? I’m hoping I’ve failed on the research/Google front and there’s a great way to do this via baked in methods.