Assign material to multiple objects

Is there a way to assign a material to multiple objects at once?

Q

In the Editor it’s as simple as adding a component to multiple objects:

  1. Select all the objects you want to modify in the Hierarchy.
  2. Drag the Material you wish to assign from the Project View to the Inspector(Beneath any existing components).
  3. For me this applies the Material to all selected objects.

Note: It does not work that way if you drag the material to the Scene View, in that case it only gets applied to the one your mouse is over, it needs to be the inspector.

Select all the Objects (In the Scene/Hierarchy), then drag and drop the wished material in the Inspector. I don’t know it that matters, but I did this just under the “Add Component” button.

Hope this will help :slight_smile:

I wrote the following code that helped me. Just save the following code in a C# file named “AssignMaterial”. This adds a Assign Material option in the GameObject menu.

using UnityEditor;
using UnityEngine;
using System.Collections;

public class AssignMaterial : ScriptableWizard {

    public Material material_to_apply;

    void OnWizardUpdate ()
    {
        helpString = "Select Game Objects";
        isValid = ( material_to_apply != null );
    }

    void OnWizardCreate ()
    {
        GameObject [] gos = Selection.gameObjects;
        foreach( GameObject go in gos )
        {
            Material[] materials = go.GetComponent<Renderer> ().sharedMaterials;
            for ( int i = 0 ; i < materials.Length ; i++ )
                materials [ i ] = material_to_apply;
            go.GetComponent<Renderer> ().sharedMaterials = materials;

            materials = go.GetComponent<Renderer> ().materials;
            for ( int i = 0 ; i < materials.Length ; i++ )
                materials [ i ] = material_to_apply;
            go.GetComponent<Renderer> ().materials = materials;


        }

    }

	[MenuItem("GameObject/Assign Material", false, 4)]
    static void CreateWindow ()
    {
        ScriptableWizard.DisplayWizard ("Assign Material", typeof(AssignMaterial), "Assign");
    }
}

I hope this helps!

Write a `foreach` loop and assign the material to all your `gameObjects`. You have to specify something to create your list. Something like `FindChildren` or maybe something with tags. That all depends on what you want to find of course.

HI...my quick fix was to assign a material to one of the objects. Then modify it as needed. Then drag it onto each object. This way you wont need to re-adjust the UV etc...hope this helps

hi all....i have FOUND a solution....the Antares project has a library of add ons....this allows for multi select and apply....found it here in the forum and it really helped a lot...just requires a cup of coffee and a couple of hours to get the hang of it..but becomes a very nice add on to the inspector....link below

http://forum.unity3d.com/threads/59121-Visual-Logic-Editor-%28Antares-VIZIO%29-%28video-amp-screens%29

enjoy and i hope it helps....special thanx to the creator of the script....hope we can dish out enough to buy their VIZIO extension soon..:)

Is there a way to mesh multiple objects into one object so when I add a material it is consistent throughout all the objects? I have multiple gameobject pieces that make up the “carpet” but the multiple carpet materials next to each other doesn’t look right. I don’t think it’s a tiling issue. Sometimes when the camera hits the right spot it blinks in and looks normal.

The easiest way to apply the material to multiple game objects in Unity editor is by dragging material to mesh renderer component → Materials