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
2
Question by inewland · Jul 01, 2015 at 09:00 PM · shadertextureunity5programmatically

SetTexture Not Working In Unity 5

Unity Version (5.1.1f1)

I'm currently using the Standard Shader when creating Materials dynamically through script at runtime. When apply a texture using the method below, I'm able to see my Diffuse Texture:

 SetTexture("_MainTex", myDiffTex);

However, after attempting to apply my next 2 textures, they never get updated in the viewport:

 SetTexture("_MetallicGlossMap", mySpecTex);
 SetTexture("_BumpMap", myBumpTex);

However, once I go over to the inspector and select the dropdown for the material, everything updates and my changes are reflected in the main view. (I've attached images demonstrating this)

Is this a bug in Unity 5?

Before Dropdown After Dropdown

screen-shot-2015-07-01-at-44812-pm.png (245.0 kB)
screen-shot-2015-07-01-at-44746-pm.png (218.1 kB)
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

2 Replies

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

Answer by inewland · Jul 07, 2015 at 06:15 PM

Ok so it appears the problem was with this new thing called 'EnableKeyword'.

Because of the new nature of the Standard Sharder and how variants work, you have to actually enable the keywords that you are looking to apply to this shader.

Doing this fixed it for me:

 // For '_BumpMap'
 material.EnableKeyword("_NORMALMAP");
 
 // For '_MetallicGlossMap'
 material.EnableKeyword("_METALLICGLOSSMAP");
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 Julien-Lynge · Apr 06, 2016 at 08:50 PM 0
Share

If folks are looking for more information, I found these docs helpful:

http://docs.unity3d.com/$$anonymous$$anual/$$anonymous$$aterialsAccessingViaScript.html (near the bottom, tells you the keywords for the standard shader)

http://docs.unity3d.com/$$anonymous$$anual/SL-$$anonymous$$ultipleProgramVariants.html

avatar image
0

Answer by HappyLife · Jun 16, 2017 at 04:55 AM

I don't know why,but after i invoke SetTexture twice the problem is solved and the texture of material is updated

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 JonPQ · Nov 22, 2017 at 06:51 PM 0
Share

I have same problem, unity 5.6.3.p3 have tried both keyword, and calling SetTExture twice.. adding keyword, fixed problem for android. but on iPad3 still not working.... though things work on iPhone 6s. Saw same issue with it not updating in editor unless click outside editor, then click back inside to gain foxus of editor, fixed materials.... broken on device though :(

avatar image GreatCorn · Dec 21, 2017 at 08:08 PM 0
Share

I have a problem. $$anonymous$$y script is simple. All I'm trying to do is to change a texture of a material when a variable reaches specified value. if (blink$$anonymous$$eter > 90){ g_Health.renderer.material.SetTexture("_$$anonymous$$ainTex", h10); return; } However, Unity says that it was expecting ")", but found ",", so that means that it does not know that there should be a texture there. Could you please help?

avatar image JonPQ GreatCorn · Dec 21, 2017 at 10:24 PM 0
Share

is blink$$anonymous$$eter an int or float ? if float it should be 90f is h10 of type Texture or Texture2D ? it should be one of those. which line of code gets that error... can you split it out into several lines, ins$$anonymous$$d of one long line

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

25 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

Related Questions

Writing a shader for a terrain? 0 Answers

Changing material in code doesn't update shader 3 Answers

Is it possible to create a shader that emits light into the world? 0 Answers

Cutout Material is not showing texture transparency? 0 Answers

Noob Question - Custom trees and aliasing 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