Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 bowditch · Apr 05, 2010 at 04:59 PM · shadertexturedefaultshader-replacementself-illumination

Is there a way to change the shader on all meshes without doing it manually one by one?

I have dozens of meshes textured off of photograph-based UV sets. My team has created a self-illumination shader that allows the textures to produce the game lighting (Example - An office building texture with a self-illum shader mirrors the lighting from the photograph.)

When I import the meshes in Unity from Maya 2010, it defaults all shaders to diffuse.

Is there a way to replace all of the shaders assigned to all of the meshes in a batch like process; Or, can a default shader be declared in the project that forces Unity to use self-illumination as the default?

Any ideas or resource guidance on this issue will be helpful. Thanks!

Comment
Add comment
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

3 Replies

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

Answer by Eric5h5 · Apr 05, 2010 at 07:52 PM

Use this editor script on the wiki to mass-assign materials.

Comment
Add comment · Show 2 · 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 cregox · Jan 07, 2013 at 07:53 PM 0
Share

In Unity 4 this is obsolete. :-)

avatar image aormsby · Jul 02, 2015 at 12:57 AM 1
Share

I just added a post down below with a link to an editor extension on the Asset Store that actually does this stuff. I'll add it in here as well in case anyone wanders through here - Legacy 2 PBR

avatar image
2

Answer by cregox · Nov 23, 2011 at 08:32 PM

Since we can't easily list all shaders, using a TextField is the best I've got, after modifing the script from wiki:

 using System;
 using UnityEditor;
 using UnityEngine;
 
 class MassMaterialEditor : EditorWindow
 {
     static MassMaterialEditor window;
     
     String oldShaderName;
     Color oldMainColor;
     Color oldSpecColor;
     float oldShininess;
     Texture2D oldLightmap;
 
     [MenuItem("Character Generator/Mass Material Editor")]
     static void Execute()
     {
         if (window == null)
             window = (MassMaterialEditor)GetWindow(typeof (MassMaterialEditor));
         window.Show();
     }
     
     void OnGUI()
     {
         Shader shader = Shader.Find(EditorGUILayout.TextField("Shader", oldShaderName));
         if (shader != null) if (shader.name != oldShaderName)
         {
             oldShaderName = shader.name;
             SetProperty("_Shader", shader);
         }
 
         EditorGUILayout.Separator();
         GUILayout.Label("--- Render Settings ---");
        
         RenderSettings.fog = EditorGUILayout.Toggle("Fog", RenderSettings.fog);
         RenderSettings.fogColor = EditorGUILayout.ColorField("Fog Color", RenderSettings.fogColor, GUILayout.Width(140));
         RenderSettings.fogDensity = EditorGUILayout.Slider("Fog Density", RenderSettings.fogDensity, 0, 1);
         RenderSettings.ambientLight = EditorGUILayout.ColorField("Ambient", RenderSettings.ambientLight, GUILayout.Width(140));
 
         EditorGUILayout.Separator();
         GUILayout.Label("--- Material Settings ---");
         GUILayout.Label("Selected Materials are modified");
 
         Color mainColor = EditorGUILayout.ColorField("Main Color", oldMainColor, GUILayout.Width(140));
         if (mainColor != oldMainColor)
         {
             oldMainColor = mainColor;
             SetProperty("_Color", mainColor);
         }
 
         Color specColor = EditorGUILayout.ColorField("Spec Color", oldSpecColor, GUILayout.Width(140));
         if (specColor != oldSpecColor)
         {
             oldSpecColor = specColor;
             SetProperty("_SpecColor", specColor);
         }
 
         float shininess = EditorGUILayout.Slider("Shininess", oldShininess, .01f, 1, GUILayout.Width(250));
         if (shininess != oldShininess)
         {
             oldShininess = shininess;
             SetProperty("_Shininess", shininess);
         }
 
         Texture2D lightmap = (Texture2D)EditorGUILayout.ObjectField("Lightmap", oldLightmap, typeof(Texture2D));
         if (lightmap != oldLightmap)
         {
             oldLightmap = lightmap;
             SetProperty("_LightMap", lightmap);
         }
     }
 
     static void SetProperty(string prop, object value)
     {
         foreach (Material m in Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets))
         {
             if (value is Shader)
             {
                 m.shader = (Shader)value;
                 continue;
             }
             
             if (!m.HasProperty(prop)) continue;
 
             if (value is float)
             {
                 m.SetFloat(prop, (float)value);
                 continue;
             }
             if (value is Color)
             {
                 m.SetColor(prop, (Color)value);
                 continue;
             }
             if (value is Texture)
             {
                 m.SetTexture(prop, (Texture)value);
                 continue;
             }
             throw new Exception("Unexpected type for " + prop + ": " + value.GetType());
         }
     }
 }

Comment
Add comment · 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
0

Answer by qJake · Apr 05, 2010 at 05:11 PM

Well... for starters, I'm sure you could write an Editor script to do it for you. Here's the class overview for Editor scripts:

http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.Editor_Classes.html

Unfortunately, Unity doesn't support multi-select editing (yet), so if you can't find a solution, you may just have to suck it up, throw on some music, and do it manually.

You could also try exporting some other way from Maya... instead of using the Maya format, you could try .FBX (or the other way around). Unity may import the materials differently using different file formats.

Comment
Add comment · Show 2 · 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 Eric5h5 · Apr 05, 2010 at 07:52 PM 1
Share

@SpikeX: Unity doesn't import $$anonymous$$aya files, it opens $$anonymous$$aya in the background and makes it export to .FBX. So there is no difference. Anyway Unity doesn't import materials from 3D apps at all, because there's no real way to convert them.

avatar image qJake · Apr 05, 2010 at 11:51 PM 0
Share

One of the few types of model files it doesn't import then... strange. :P

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

2 People are following this question.

avatar image avatar image

Related Questions

Self-Illuminated Normal mapped Specular Shader questions 1 Answer

Encoding Float to RG/RGBA and Blending 0 Answers

modify one color of a texture 2 Answers

Create a drag and drop element in the custom editor for textures. 1 Answer

Textures missing after extended gameplay on Playstation game,Missing Textures after extended play on Playstation 4 game 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