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
24
Question by Avaista · Mar 18, 2012 at 02:43 AM · materialrenderersharedmaterial

Material Versus Shared Material

I am working with the renderer for the very first time and I wanted to make sure that I understood exactly how these work and the difference between the two.

From what I understand and can see from tests, renderer.sharedMaterial returns the actual instance(s) of the Material at renderer.sharedMaterials[0] that is on the object. This can be modified, and it will affect every use of this Material in the Scene.

renderer.material, on the other hand, creates a copy of renderer.sharedMaterials[0], which then replaces the original in renderer.sharedMaterials[0], and returns this new material. A duplicate object from the scene will not be affected to changes made to this material, and changes made by said duplicate object to it's respective renderer.sharedMaterial[0] will not affect this new copy.

render.sharedMaterials returns the actual array (well a copy of the array(not the materials just the array)) of the materials. This particular array only applies to that particular renderer. Though the materials are shared, the arrays are not. Removing or adding a material to this array will not change any of the other objects in the scene. Changes to the materials them selves, however, will.

render.materials copies each Materials from renderer.sharedMaterials, replaces the originals with the copies in the array, then return a copy of the new array back. Again any of these materials can be manipulated without affecting or being affected by changes to the original material.

I hope that was not too long.

Do I have all of this correct, is there anything I am missing? I know this is not much of a question, per say, but I was left unsure from the Unity documentation. I apologize if I have taken an unfair amount of your time.

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 trapazza · Feb 11, 2013 at 03:47 AM 0
Share

Actually this question proves how poorly designed some APIs are.

2 Replies

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

Answer by rutter · Mar 19, 2012 at 01:20 AM

From what I know, your understanding sounds right.

You may want to stress test these assumptions before using them in production, though. Among other things, I don't know if copying all of those materials may be a performance problem.

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
7

Answer by Pratap-Dafedar · Feb 20, 2014 at 02:48 PM

It is because suppose someone want to change the material colour or texture, then it should not effect original material. So renderer.material will be used. And If you want to do so, then use renderer.sharedmaterial. So, It is flexibility from unity API, not a weakness.

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

6 People are following this question.

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

Related Questions

Changing two different objects renderer colour 1 Answer

SetPropertyBlock doesn't work for particle systems? 0 Answers

Why does my materials get destroyed on some persistant objects ? 2 Answers

How would I change the color of a texture within an object with multiple textures? 1 Answer

Emissive Material control via script (code) 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