Is there a way to mass assign materials?

this should quite basic. is it possible to do it in editor ?

Thanks

There's no built-in script to do it, but if you're familiar with scripting at all, it should be fairly easy to make a script to automate it.

You can use the @MenuItem attribute to create a menu item at the top of the editor which calls a certain function. Then you can use Selection.gameObjects to get a list of selected GameObjects, loop through them, and set all of their materials to whatever you want.

NOTE: Make sure the script is in the Assets/Editor folder, otherwise you can't use the Editor classes (MenuItem and Selection in this case), and will get errors.

EDIT: Here's a quick script I made to do this:

@MenuItem("Scripts/Mass Set Materials")
static function MassSetMaterials() {
    Undo.RegisterSceneUndo("Mass Set Materials");

    var mats : Material[] = Selection.activeGameObject.renderer.sharedMaterials;

    for (var obj : GameObject in Selection.gameObjects) {
    	obj.renderer.sharedMaterials = mats;
    }
}

To "install" it, just create an empty JavaScript in your project, call it "MassSetMaterials" or something similar, and put it inside the "Editor" folder (which you'll also have to create if it doesn't already exist".

Basically, what it does is to set the materials of all currently selected objects to be the same as the materials of the currently active object (the one shown in the Inspector). So to use it, just change the materials of one of the objects to whatever you want, the hold Control and select the other objects you want to change (the object you changed manually should still be shown in the inspector on the right), and click Scripts > Mass Set Materials. All the selected objects should then have the same materials.

A couple things to note:

First, I haven't tested this script beyond just making sure it works. However, I have made the script so that everything it does can be reversed by hitting Undo.

Second, the script uses RegisterSceneUndo for the undo functionality. While this makes it so that everything that the script does can be undone, it can also take up a lot of memory if you use it many times in a large scene (I'm not sure if Unity limits the size of the Undo cache).

If you have any problems with slow downs after using the script repeatedly, you may want to comment out the RegisterSceneUndo line. Note, however, that if you do this, you will NOT be able to reverse the effects of the script by hitting Undo.

I tried to get it working by using the RegisterUndo function instead, which only stores undo data for the specified objects (thus saving on memory), but I couldn't get it to work for some reason.

Works Great, Neat! I guess that these is a reason that they don't add things like this built in, cos they have the users like you guys?

Anyway, Thanks very much. Btw, I am the one who asked the question, just got a proper login.

Oop I posted in the wrong place cant delete..sorry (

Doesn't seem to work for me.. I followed instructions correctly but Im getting this error in Console: " NullReferenceException Mass Set Materials.MassSetMaterials () (at Assets/Editor/Mass Set Materials.js:7) "

and here is the exact copy of the code active in my project:

@MenuItem("Scripts/Mass Set Materials")
static function MassSetMaterials() {
    Undo.RegisterSceneUndo("Mass Set Materials");

    var mats : Material[] = Selection.activeGameObject.renderer.sharedMaterials;

    for (var obj : GameObject in Selection.gameObjects) {
        obj.renderer.sharedMaterials = mats;
    }
}

Any Ideas?