- Home /
Can you assign a material to all Items within an Empty Game Object at once?
Is there a way to assign a material to the items within a Empty GameObject without having to texture them 1 by 1? I am still a newbie and have been working with ProBuilder, so I would appreciate a solution that does not require me to mess with the code. I am dealing with gameObjects that have over 100 items each.
Answer by nicolasjr · Apr 13, 2014 at 01:38 AM
I think this should do it:
foreach(Renderer r in GetComponentsInChildren<Renderer>()}
{
r.material = yourMaterial; //Set material.
}
Let us know if it worked as you intended!
Three questions: 1. Where do I apply this code? 2. What parts of the code do I need to change myself, and which parts do I leave alone? and 3. Is there a simple way for me to do it while staying in ProBuilder itself?
Ok, since you answered this question, i now know how to write, attach, and run scripts. This works great thanks. Though i would still like to know if it is possible to do it straight from the editor/ProBuilder
Your answer
![](https://koobas.hobune.stream/wayback/20220613142600im_/https://answers.unity.com/themes/thub/images/avi.jpg)