Goal
I created a shader graph that I use in a material "TestMaterial". I have a game Object with a sprite renderer component with a default material property.
At runtime when user click on a simple button I want to change my gameObject > Sprite renderer > Material property "default" with my new material "TestMaterial".
Context
I use Universal Render Pipeline and Unity 2019.4.12.f1. My code worked well before I use the function Edit > render pipeline > universal render pipeline > 2D renderer > Update project to 2d renderer.
Tests I made My "TestMaterial" work well in editor and also at runtime when my gameobject use directly this material. "TestMaterial" doesn't work only if I update material in my script, my gameObject keep old default material.
Code
[SerializeField] Material testMaterial;
[SerializeField] Material defaultMaterial;
public void UpdateToDefaultMaterial()
{
this.gameObject.GetComponent<SpriteRenderer>().material = defaultMaterial;
}
public void UpdateToTestMaterial()
{
this.gameObject.GetComponent<SpriteRenderer>().material = testMaterial;
}
Screenshot Unity Editor