Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity 2018.3 HDRP - Change material color programatically?

I am using the new HDRP/LitTesselation shader.

I would like to change the Base Color + Opacity at runtime:

img

I added this code to the game object's script:

void start()
{
        Color color = new Color(100, 50, 100, 150);

        //Fetch the Renderer from the GameObject
        Renderer rend = GetComponent<Renderer>();

        //Set the main Color of the Material to green
        rend.material.shader = Shader.Find("_Color");
        rend.material.SetColor("_Color", color);
}

But it generates an Hidden/InternalShaderError error in the shader. Can anyone point me in the right direction?

like image 569
T1000 Avatar asked May 28 '26 19:05

T1000


1 Answers

I got it working by modifying these lines as follows:


rend.material.shader = Shader.Find("HDRenderPipeline/LitTessellation"); 
rend.material.SetColor("_BaseColor", color);

like image 95
T1000 Avatar answered May 31 '26 10:05

T1000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!