Hi, I need to add a gameobject and all its children to a layer via c# code. In editor i'm asked if i want to add the single object or the whole hierarchy. i wonder if there is an equally fast way to do this in a script without writing explicit code
asked Sep 02 '10 at 01:55 PM
To put a stop to your wondering, the short answer is that there is no implemented method to do this that I can find.
As == says, you will have to recurse through the hierarchy.
You could do something like:
There is no reason you couldn't recursively move down the top-most object's transform hierarchy and set each gameobject's layer accordingly.
Add this script to your Editor folder: