Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by qholmes · Apr 06, 2011 at 04:55 PM · materialassign

Assign material to multiple objects

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

Q

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bampf · Apr 06, 2011 at 05:11 PM 0
Share

In the editor, or in a script?

8 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Marnix · Apr 06, 2011 at 05:06 PM

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image qholmes · Apr 06, 2011 at 05:48 PM 0
Share

So i am getting the feeling that a lot of the things i want to do like basic things that i personally think should be in the editor need to be done via scripts.... Strange but i guess i had better just get over it...

Thanks!!

avatar image Marnix · Apr 06, 2011 at 06:01 PM 0
Share

@quentin: If you want this to happen in the editor, you will see that a lot of problems arise. What do the selected items do with the new material? Replace the old? Or add an extra material? It's too specific to just say: assign.

avatar image qholmes · Apr 06, 2011 at 08:05 PM 1
Share

Well if i drop a material on a single object it replaces the existing one.... just like i wanted it to. But if i have 20 of them ins$$anonymous$$d of being able to just select the 20 which is no problem if i drop a material on that group it just does the one where it is dropped... not rocket science i would not think... but it just seems that all the little tweaking things that i want to do like rotate the uvw etc all has to be done with a script. I guess i would say that a basic set of controls is missing from the editor..

avatar image qholmes · Apr 06, 2011 at 08:08 PM 0
Share

But who wants to write a script for something like the ability to put a material on multiple objects even though it would save you 20 $$anonymous$$ I am sure once i get into the habit of writing little scripts for everything maybe i wont think twice..

avatar image Marnix · Apr 06, 2011 at 10:24 PM 0
Share

@quentin: You could always ask Unity for a support on these little features. It seems indeed that something simple like this would be appreciated. For most of it, I don't like it to be in editor, I prefer the scripts. This will keep an overview of what is actually there and what is done. If everything is already set inside the scene, you lose grip of your scene. Someone can't read what you did, because it's all binary. There is no way to find back what is in your scene-files. Creating worlds in a procedural way keeps your project clean.

Show more comments
avatar image
18

Answer by o_oll · Nov 10, 2012 at 08:20 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image entity476 · Apr 15, 2013 at 07:33 AM 0
Share

I am not sure if this was true with older Unity versions (like the one when the question was asked), but I totally agree that currently this is the way to do it.

I should only notice that this procedure (multi-editing) works, when ALL the selected objects share the same to be edited components. In this case, it's the mesh renderer component, which needs to be shared by ALL the selected objects. There's even a warning appearing on the Editor, when objects without common components are selected.

In addition, the editing doesn't apply, if the material is assigned to the parent objects directly. If, for instance, an object (or multiple of them) with a mesh component is parented to an empty object, then the object with the mesh itself should be selected, in order its material to be edited and not the parent.

This said, I assume that the difficulty, anymore, is to select all these objects you want to edit. Though I guess (unless there's no worry to be done by script) some proper hierarchy structure could solve this issue.

Please correct me if I'm wrong.

avatar image absynce · Dec 16, 2013 at 09:53 PM 0
Share

This worked for me.

avatar image DarkNode · Oct 01, 2017 at 08:23 PM 0
Share

Thanks o_oll you just saved me a ton of time!

avatar image thomasmking1990 · Oct 07, 2017 at 06:02 AM 0
Share

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. ![alt text][1] [1]: /storage/temp/103266-carpetissue.jpg

carpetissue.jpg (399.7 kB)
avatar image
3

Answer by Saraf · Jun 06, 2014 at 08:25 AM

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 :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image clinton_d · Jul 04, 2019 at 05:59 AM 0
Share

Thanks Saraf!

The trick is to drag the material beneath the "Add Components" button, as you suggested. If you don't, it won't work!

Here I was thinking I had already tried all possible permutations to get this to work :\

avatar image
3

Answer by shaan24 · May 23, 2016 at 02:05 PM

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zukias · May 05, 2021 at 06:18 AM 0
Share

where do you save this file?

avatar image
0

Answer by MohdGasim · Apr 10, 2011 at 09:24 PM

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image qholmes · Apr 11, 2011 at 03:49 PM 0
Share

Well that is kind of how i do it now actually... But my current model is a mechanical assembly and there are tons of small objects all hidden here and there. I think normally i would not have a problem with it but i did not export the model myself or i would have set up the materials better in $$anonymous$$ax... i will do it next time. And i did notice in the Unity Store that there are a few scripts for doing exactly what i was asking to do so there you go, just buy an editor script or write one i think is my answer

avatar image MohdGasim · Apr 13, 2011 at 11:46 AM 0
Share

well...it might be still easier to just re-import the file in max..fix it up..and then export to FBX including the textures (embed media)

avatar image Anxo · Apr 27, 2011 at 03:54 PM 0
Share

I have the same problem. But $$anonymous$$e is a city to I have hundreds of buildings. It is a point dragging the material to every object.

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I assign materials using C# code? 5 Answers

Setting sharedMaterial only setting for one object? 1 Answer

how can i assign a material to a 3d model? 1 Answer

Assign Material by script: Javascript? 1 Answer

How can I assign an existing material to a prefab? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges