I am trying to change a material property runtime, the value changes in the inspector, but the change does not happen to the material itself. Alt+tabbing out of the editor and back in propagates the changes.
I am using this bit of code:
Material[] mats = renderer.materials;
foreach (Material mat in mats)
{
mat.SetFloat("_DITHERING", 0);
}
Assingning the array of materials to the renderer like
renderer.materials = mats;
Also didnt change the result. I also tried material property blocks.
renderer.material/renderer.materials creates a copy of the material/materials and returns that. It’s there as a convenience to only change the material(s) of a single renderer.
If you want to change the material asset, use renderer.sharedMaterial and renderer.sharedMaterials respectively.