New to coding, I have a huge model that was imported from other software, I want to apply different Render materials to various GameObjects, but selecting them and all the children is time consuming. Since the names of these GameObjects have a common part in the name for the render applied I wanted to see if I can script this and make it a standard in my model. Example below to illustrate what I’d like to do, I’ve read about using find commands etc, but everyone says this isn’t the best as its slow so hoping to learn more.
My GameObjects are named like this:
I want to apply one Material “Grating” to everything that is a PANEL and another Material “SteelBlue” to everything called SCTN. I want this repeated over the whole model not just this little section so I’d apply the script to the scene.
I mean, this is certainly possible through scripting, and even better, through editor scripting, so performance isn’t as big a deal. You’ll pretty much want to use GetComponentsInChildren() on the top-level object, loop through the results, and check each component’s gameObject.name to see if it’s one you want to be changing using something like a regular expression evaluation or String.Contains if your test is simple enough.
I will say that this many objects on a set of stairs is troubling. I’m guessing this was made in some type of arch-viz or BIM program? I had issues when trying to load large BIM models into Unity, but hopefully your models are better optimized than mine were.
Thankyou for the Reply and Info! I shall have a go at the script and see if i can get it running.
I agree the number of objects isn’t the best, but you are correct! this model is an import from another program so having to deal with what I get for now. Once I get more experience I shall try to replace certain things and optimise the model, but for now the goal is make it pretty and use it. probably doing things the wrong way round but have to for now