How to get material and also keep MaterialPropertyBlock of the material?

I’m using Unity 2018.1. I follow this tutorial to apply MaterialPropertyBlock for a game object. I use MaterialPropertyBlock to generate random color for my shared material.


I know that:

  1. when I call MeshRenderer.materials, Unity’ll generate the material for the specify object (The material names now have the suffix (Instance))

  2. when I call MeshRenderer.sharedMaterials, Unity’ll just return the original material (if you change anything for this material, it will directly update to your asset file)


But both method materials and sharedMaterials doesn’t give me the material that has the MaterialPropertyBlock (color). Both return the material with the original color. Is there anyway I can get material and also keep MaterialPropertyBlock of the material?

It doesn’t work like that, the MaterialPropertyBlock is for per-render object. If you create instance (using Instance()) for a GameObject that has MaterialPropertyBlock, you still have to “re-paint” MaterialPropertyBlock for the new Instance.