Digging component system further…
Now lets discuss GameObject.components and GameObject.children.
Components are quite simple to understand. It’s just partitioned functionality of a GameObject.
But what about Children?
Unity uses Children objects as Transform increment, i.e. Physical parts of a GameObjects. But what else it could be?
Could Children be Components? Why not, but why?
Components could be GameObjects and vise-versa. Because of new assumption: “GameObject can have Representative Component”, or another words “GameObject can have custom code realization, like inheritance”.
=> GameObject.components = GameObject.children.
The only difference that by default Unity assume, that Components are part of an Object, and Children are separate objects, connected only by Transform’s logic.
What i want is to expand Children’s role:
- Childrens are also Objects created by Object (by it’s Components).
- Childrens are also Objects contained by Object (by it’s Components).
- Childrens are also Objects temporally created by Object (by it’s Components).
=> Children of a GameObject = Children of Components (AND/OR) Contained by Components.
Technically ofcource we always use GameObject parenting like this, but what is missing in Unity, is: built-in “Per Component parenting”, instead we have “Mixed” Children for All Components at once and have to arrange all those children manually.
So what i did in short:
I assumed that each GameObject can have “Representative Component” (or GameObject’s code body), for ability to Script entire GameObject.
Now i have the following architecture of a GameObject:
(GO have RC) have Components have Children.
GO+RC = ScriptableGameObject.
Components = Components of ScriptableGameObject.
Children = ScriptableGameObjects of All Components.
This is my approximation to solve problem. What i did is only added additional “Representative Component” semantics.
What is still missing: individual Components can’t automatically have Children objects, instead all objects placed in a single bin object’s “Children”. But i can manually create Child GameObject with similar name as Component, so this could have meaning of Children Folder for particular Component. Perhaps in some situations this could be “plus” rather than “minus”, because common Children for all dont have so much Hierarchy, as for Children per each Component.
Anyway, even if my problem is approximately solved now. Perhaps Unity should change architecture of GameObject, to allow it to be Extended by Code via Inheritance, like Component(MonoBehaviour) + also have like Component Body inside of Inspector.
Conclusion:
- GameObject should inherit MonoBehaviour (or Component), and also GameObject should be not sealed. To allow GameObject to have code Body.
- Transform should not be a Component, but part of GameObject’s Body (or Interface) instead.
i.e. GameObject’s Body - is like-component body meaning.
In short: GameObjects should be able to have different code Types, like different Components. (may be i am wrong, needs investigation)