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
0
Question by kdubb · Sep 07, 2011 at 08:09 AM · materialmeshrenderersharedmaterial

Why does reading MeshRenderer.material change MeshRenderer.sharedMaterial?

I am trying to lookup materials by name and set a texture. My first attempt was

 if(renderer.material.name == "My Material")    
    renderer.material.SetTexture(newTex);
 

... then I noticed the " (Instance)" attached to the material's name (e.g. renderer.material.name == "My Material (Instance)"). So my second attempt was

 if(renderer.sharedMaterial.name == "My Material")
    renderer.material.SetTexture(newTex);

... this works... the first time.

Unfortunately the second time I call my function I noticed that the renderer.sharedMaterial's name is now equal to "My Material (Instance)". In other words, after any call to renderer.material the renderer.material == renderer.sharedMaterial.

Can somebody explain this? Once I access renderer.material how can I access the original renderer.sharedMaterial? Shouldn't sharedMaterial always point to the original shared material?

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 Evil-Dog · Sep 26, 2011 at 07:35 PM 0
Share

I'm wondering the same thing, there's no reason why reading the alpha of material should suddenly create a new instance. Any more thoughts on this? I'm trying to avoid creating material instances here while I animate various body parts in a character, so when the alpha is 1, I check if the material's alpha is 1 already before trying to modify it, but that check defeats my purpose and does create an instance. Doesn't make sense.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by roamcel · Sep 07, 2011 at 09:26 AM

This is actually a "buglike" feature, which you can identically reproduce for other self-iterating 'types' like prefabs (and their transforms in particular). In your case, newtex creates a new instance of the material, and thus changes the reference!(brain freeze). http://answers.unity3d.com/questions/159889/brain-freeze-declaring-a-prefab-inside-the-same-pr.html

You can work around it with something like

 newTex = myparent.newTex;

immediately after you instantiate the object. But it's quite probable that you'll need to refactory a bit to avoid headaches.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Material vs. SharedMaterial - difference in SETTING? 1 Answer

Change specific material on an object with multiple materials?,Change specific material on an object in a script? 0 Answers

Changing Texture of Material of Meshrenderer creates Instance in Start() but not in Update(), just see blue dots 1 Answer

Directional Light seems to have no effect on MeshRenderer. 1 Answer

Why isn't (.)sharedMaterial sharing this change to "_EmissionColor"? 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