Hello,
Using the Per Instance Material Properties example scene, I'm trying to change the Stencil Comparison function of the material on a per-instance basis using the MaterialPropertyBlock approach as you are with SetColor.
I altered the code in the example script like so:
void Update () {
if (timeToNextColor <= 0){
timeToNextColor = timeInterval;
Color newColor = randomColors.Evaluate(UnityEngine.Random.value);
mpb.SetColor(colorPropertyName, newColor);
mpb.SetFloat("_StencilComp", Random.Range(0, 2) == 1 ? 1.0f : 8.0f);
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
}
timeToNextColor -= Time.deltaTime;
}
Using these values (1 == NEVER and 8 == ALWAYS) the enum in the material inspector updates at runtime but there is no effect on the rendered character in the game view. If I manually click on the Stencil Comparison drop down and change it to never, the character immediately becomes invisible like I'm hoping for. Any idea why changes to SetColor would work as expected but not SetFloat for the Stencil Comparison? I've also found that changing these properties using meshRenderer.material does have the expected result at runtime but creates a new material instance.
Seems like I found my answer: