• 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 /
  • Help Room /
avatar image
1
Question by dmm_jbw · Apr 20, 2016 at 07:58 PM · scripting problemshadermaterialresources

Specular Material Not Updating, but Standard is ok?

I am creating and assigning materials dynamically in my pipeline. This works well for all use with the Standard Unity shader. However, when I use the "Standard (Specular Setup)" shader, then the material is all black until I select the material in some way so it's displayed in the inspector.

Now, this question has been asked a couple of times and the answer is to make sure that the material has the correct keywords enabled. Well, I do that. In the case of the specular setup, it's going to have:

 mat.EnableKeyword("_SPECGLOSSMAP");
 mat.EnableKeyword("_NORMALMAP");

So, unless this shader is different than the "Standard" one, then I don't think they way I'm constructing the material is a problem.

I'm guessing the issue is something with it not being referenced or a loaded resource until it's selected.

Perhaps something in my assignment code? That looks like this:

 Object[] matchingModels = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Where(a => a.name.Equals(meshName)).ToArray();
 foreach (var model in matchingModels)
 {
     GameObject gameModel = (GameObject)model;
     if (gameModel != null)
     {
         Renderer r = gameModel.GetComponent<Renderer>();
         if (r != null)
         {
             r.sharedMaterial = myCreatedMaterial;
         }
     }
 }

I'm not quite sure what else to try. Any suggestions?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by dmm_jbw · Apr 20, 2016 at 11:51 PM

For anyone looking for the answer, keywords were STILL the problem and answer.

I was specifying mat.EnableKeyword("_SPECGLOSSMAP") even in the case where I was only looking for specular colour. By enabling the keyword, but NOT setting a texture to _SpecGlossMap it caused it to appear black.

Selecting the material in the inspector must have brought some sanity here and cleared the keyword.

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 Artaani · Dec 13, 2016 at 12:49 PM 0
Share

Hello. Thanks you for the answer on own question.

Today I encountered with the same problem, decided to check Unity Answers by entering "_SpecGloss$$anonymous$$ap" and seems like you saved my nerves and time and I have avoided a lot of thinking about "Why it does not works?!" : )

Thanks.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

77 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script to find material and textures of selected prefab 0 Answers

Material.SetFloat not updating. 0 Answers

LWRP - Proper way to set up LWRP Standard and Simple lighting shaders? 0 Answers

How to fix these errors when launching a built game 0 Answers

Is there a shader I could use to always render a material over another material? 0 Answers


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