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)
Assingning the array of materials to the renderer like
renderer.materials = mats;
Also didnt change the result. I also tried material property blocks.
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
I want to change the material properties of a single renderer. Using shared materials changes every instance of it, so that is not an option.
Changing .material changes the property in the inspector as I described in the post, but not in the game or scene view
Is your editor by any chance paused, or in any other way not updating/rendering? I think a frame needs to pass until the change becomes visible.
Alt+tab causing the change to apply sounds like something is failing to update properly.