Assign large amounts of materials in Unity!

We at Bully try to keep our 3D models as optimized as possible, but sometimes a complex object hierarchy is a little hard to avoid. We recently ran into one such model when working on a project in Unity. The problem was that the model had quite a large number of mesh renderer components in Unity. Each mesh renderer needed the same material, but unfortunately when Unity imports an FBX model from Maya, the materials don't come along with it. We quickly realized that dragging and dropping a material onto every single GameObject with a mesh render was going to take quite a long time.

Enter: Mass Material Assigner!

The Mass Material Assigner script is a utility for Unity. It assigns a material to every single mesh renderer component that is a child of a selected GameObject. Basically, it allows you to quickly assign a material to any number of mesh renderers at once.

To help explain how the utility can be used, we put together an example usage scenario with some images! We have a room full of geometry that is broken into 4 separate mesh renders. They are all children of one GameObject (creatively named "GameObjectA"). In the scenario, the first step was applying a "black" material to "GameObjectA".

The Mass Material Assigner finds all the mesh renderer children of "GameObjectA" and assigns them the "black" material. Because all 4 mesh renders are children of "GameObjectA", all 4 mesh renderers are assigned the "black" material.

The next step was to apply a "blue" material to "GameObjectB". "GameObjectB" only contains 2 of the mesh renderers, so the "blue" material was only applied to those 2 mesh renderers.

Obviously, in a scene like this, having a Mass Material Assigner doesn't really save too much time - but you can imagine how much time it saves for objects with more than 10 or 20 or 100 mesh renderers.

Hopefully you Unity folks out there can put this script to good use. Happy material assigning!!

Download the script here! (click save-as)