How to get the spriterender default material in the code

Hi.
I’d like to change the material of my spriterenderer if the player select a unit.

I created my shader, and my material.

So if I want to set the shader I simply add:

spriteRenderer.material = myMaterial;

How can I reset it to default material?

I tried by storing it afterhand by adding:

Material defaultSpriteMaterial = spriteRenderer.material;
spriteRenderer.material = myMaterial;

Then I would simply readd it after player deselects the unit.
spriteRenderer.material = defaultMaterial;

But it is not working.

Is it possible to access the “Sprites_Default” material in other ways?

Hi there. What about assigning the deafult material to an variable in editor. I mean something like this:

public Material deafultMaterial;
public Material yourMaterial;

Simply click on the circle on the right side of your instance in the inspector and add deafultmaterial to it. I think this is a easier way to reset the material and add yourMaterial:

    void ResetMaterial()
    {
        GetComponent<SpriteRenderer>().material = deafultMaterioal;
    }
void ChangeMaterial()
{
GetComponent<SpriteRenderer>().material = yourMaterial;
}