I would like to get the original color of the renderer material when a gameobject is instantiated and store that. From what I understand the below method is quite inefficient since it will create a new instance of the material just to store the original color (calling renderer.material always creates a new instance apparently?):
Renderer renderer = GetComponent<Renderer>();
Color originalColor;
originalColor = renderer.material.color;
The above works correctly btw and if we output original color it shows as white which is correct. I would prefer the more efficient approach however. So instead I believe I should use MaterialPropertyBlocks like this:
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
renderer.GetPropertyBlock(mpb);
originalColor = mpb.GetColor("_Color");
However now originalColor comes back as completely black color (0,0,0,0), instead of the actual color of the material. Does anyone know why?
Note if we do:
mpb.SetColor("_Color", Color.green);
renderer.SetPropertyBlock(mpb);
it will change the color on the material to green successfully in the inspector as well as in the actual game, so we know that “_Color” must be the correct name and its not that that property doesnt exist. Also oddly enough doing that does not change the value of renderer.material.color as can be accessed in the script. No idea why that is, since I would assume changing the color using propertyblocks would also change the value of material.color.
Any ideas how to store the original color using property blocks instead of material.color?