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:

!(https://i.imgur.com/X8QBlTe.png)

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

void start()
{
    Color color = new Color(0.5f, 0.5f, 0.1f, 0.8f);

    //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?

You are trying to find a Shader named “_Color” and set the shader to that, which probably dont exist.
Try the name of the shader instead like this:

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

Hello, is it possible by anyway to change the base map texture programmatically? thanks.

This works for me finally

‘red’ can be Color.red or whatever you want.

public class MaterialTest : MonoBehaviour
{
[SerializeField]
public Material myMaterial;

//public GameObject Sphere;

[SerializeField]
public Renderer rend;

[SerializeField]
public Color red = new Color(255, 0.4f, 0.6f, 255f);


// Start is called before the first frame update
void Start()
{
	
	
	//Set the main Color of the Material to green
	rend.material.shader = Shader.Find("HDRP/Lit");
	rend.material.SetColor("_BaseColor", red);
	
	
}