I have already tried really much with all "GetChildren" and similar functions, but I haven't found out how to do it yet.
I have a GameObject named "koffer". I have added several other GameObjects as children to it.
I have added a script to "koffer" in which I try to retrieve the children. In this script I have stated this line:
string sThis = this.name; //just for testing. "sThis" becomes "koffer", so it looks perfectly fine.
foreach (GameObject g in this.GetComponentsInChildren<GameObject>()) // doesn't retrieve anything. So obviously I'm not doing it correctly.
However this doesn't retrieve anything. Is this not the correct function for such a case?
Is there any built-in function to retrieve theses game obects?
I have found several custom made functions from some years ago, and I don't know if they are still needed or if Unity has integrated some functions for that.
What really bothers me is that there are so many custom-made functions that deal with "Transform" instead of "GameObject". Why would somebody need Transform instead of GameObject?
Thank you.
GameObject
is not aComponent
, so it cannot be returned byGetComponent
or its ilk. The reason the scripts you've found for the purpose of navigating children useTransform
is that theTransform
component is the one that manages the parent-child relationships you're trying to navigate here.GameObject
s do not have parents or children directly, only theirTransform
component does. That's why the tree of nested objects is called a "Transformation Hierarchy" \$\endgroup\$