0

I am trying to change shader on a trigger event during run time. However, when I used Debug.Log to check if all is right or wrong and everything runs except the shader does not change. There is something I missed ? Any help could be appreciated. Thanks very much

public void shaderChange() 
{
    rend = gameObject.GetComponent<Renderer>();
    shader1 = Shader.Find("Standard");
    shader2 = Shader.Find("Shader2");

    isActiveClip = !isActiveClip;
    if(isActiveClip == true)
    {
        rend.material.shader = shader2;
    }
    else
    {
        rend.material.shader = shader1;
    } 
}

1 Answer 1

2

The proper way to manipulate shaders is to change the assigned materials on the object. This means instancing a material for each use case and switching materials at runtime. This is because the material itself is dependent on the shader when being created.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.