Be careful; that’s the impression you’re getting, but that’s not true. It just happens that many of the “variables” of Component (all except gameObject and tag) are Properties that return components. To be clear, it would be better if they all started with capital letters, because lowercase suggests that you actually have a stored reference to the component, when in reality, the “variables” all run “GetComponent” behind the scenes.
I read through this a few times while trying to cook up the code to assign tags, it doesn’t provide any example for setting tag names to child objects in code, however. Accessing this property and changing it is the end-goal.
Thanks for the code example Jasper, I’ll check this out.
I have this working now, thanks a million. (however, grandchildren are unaffected)
Anyone know how to access the layer of a child also? Sorry to deviate from the thread title.
I tried:
for (var childl : Transform in transform) {
childl.layer = 11;
}
Obviously doesn’t work, something like this is out of the question too:
var moveLayerC : GameObject;
moveLayerC = gameObject.GetComponentsInChildren(layer);
moveLayerC = 11;
I’m only asking because child tags and layers are not inherited when dynamically changed to the parent using gameObject, and the documentation on this is lacking (or rather; my interpretation of the existing documentation), and would robustly like to know how to access tags and layers of children, without knowing their names.
No wouldn’t be neat actually it would be even worse than it is at the time.
Tags are already a “enjoy with caution” topic cause strings generate a lot of garbage so constantly working with tags can impact webplayer performance but especially on mobile it can easily become a performance killer.
Layers luckily are numbers which don’t generate trash thus are favorable if you can do it that way or alternatively having an own manager to which objects register upon startup can and should be used given you can’t use “startup caching” naturally
Most of my statements are based on complete ignorance. Wasn’t that obvious how to tag and layer child objects from unity documentation. Thanks for the advice guys.