Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the "BaseMap" property of a shader from script? - Universal RP Template

I used to change the BaseMap texture using the standard 3D project in unity as follows:

[SerializeField] private Texture texture;

void Start()
{
    this.GetComponent<Renderer>().material.mainTexture = texture;
}

However, the same code doesn't seem to work using the Universal RP Template. When I checked the shader properties, it shows that the BaseMap property is obsolete as shown in the picture below:

Shader Obsolete Properties

But when I drag and drop the texture at run time to the BaseMap, it works. I guess that means that it should work. (Below Pic):

BaseMap Texture change at runtime

My MAIN question now is, how do I change the BaseMap texture from script in Universal RP Template?

and is there other properties I should call and change their texture other than the BaseMap since it's written on the shader that the BaseMap is "ObsoletProperties"?

like image 818
Behrouz Riahi Avatar asked Oct 15 '25 14:10

Behrouz Riahi


1 Answers

Update, this should do the trick:

[SerializeField] private Texture texture;

void Start()
{
    GetComponent<Renderer>().material.SetTexture("_BaseMap", texture);
}
like image 191
Menyus Avatar answered Oct 18 '25 08:10

Menyus



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!