Change UI shader property at runtime

I have a UI Image with a material & I want to change the property of the shader/material.
gameObject.GetComponent<Image>().material.SetFloat("_highlight", 1);
works just fine but it seems to apply on my prefab shared material. I want to change the instance so I tried:

Material materialInstance;
materialInstance = Instantiate(gameObject.GetComponent<Image>().material);
gameObject.GetComponent<Image>().material = materialInstance;
materialInstance.SetFloat("_highlight", 1);

When I debug it seems that the material property has changed but I don’t see the change in game. Do I need to use CanvasRenderer.SetMaterial? I’ve been at this for over a day, any help much appreciated.

If the Image is masked, the shader stencils makes a copy of the shader. In order to reference the shader that is actually rendered on screen you need to use materialForRendering (instead of material).