HDRP changing color at runtime

Hi,
I’ve got an issue at changing the color of a material at runtime. I use the following code to set the color of the material using the HDRP Lit shader.

Renderer renderer = GetComponent<MeshRenderer>();
renderer.material.SetColor("_BaseColor", new Color(0f, 0f, 0f));

When I open the inspector during runtime, the value of the color had been changed on the material instance, but the object is not displayed accordingly (it is still displayed with the previous color). However, if I manually deactivate and reactivate the object, then the right color is displayed. Any idea on what I’m missing here ?

It’s probably because material returns a copy of the object’s material. Try using sharedMaterial instead.

I had a similar problem where after changing the texture of an HDRP material via script at runtime, the displayed material would not be updated until I modified any of its parameters via the inspector (even parameters not related to the textures I was assigning).
Using sharedMaterial instead did not solve the problem.