Changing an HDRP material's texture at run time. SOLVED - see further reply

I searched and found one other thread that also stalled with this unanswered - see here : Changing HDRP Material's Texture At Runtime Not Working? - Questions & Answers - Unity Discussions

I am using Unity 2020.1.4f1

I am trying to change the base map of an HDRP material (which is used on many different objects - buildings).

I have coded as follows (excerpt):

        [SerializeField] private Material Building_Cladding;
        public Texture Grey;
        public Texture Cladding_Waves;


// in void update

        // Geology
        if (Input.GetKeyUp("z"))
        {
            Debug.Log("Switching texture for albedo on :" + Building_Cladding.name);
            // Building_Cladding.SetTexture("_MainTex", Waves);
            Building_Cladding.mainTexture = Cladding_Waves;
            Building_Cladding.color = Color.green;
            Debug.Log("Switched color to :" + Building_Cladding.color);

        }

I added the material and the textures to my script in the editor GUI.

In my debug it states that my texture has changed. The output states :

“Switching texture for albedo on :OFA_Side_Cladding”
“Switched color to :RGBA(0.000, 1.000, 0.000, 1.000)”)

but nothing changes in the actual scene at run time.

What is the correct method to change the base map texture of a Material (which is used by many objects)? Is this a bug ?

Thanks for any help…

D.

Solution.

Contrary to what the online documentation suggests:

“_MainTex” is the main diffuse
texture. This can also be accessed via
mainTexture property.

and

By default, Unity considers a texture
with the property name “_MainTex” to
be the main texture.

the main texture map in my standard HDRP/lit shader is actually referenced by “_BaseColorMap” - AND NOT “_MainTex”.

I found this out by looking into the HDRP/lit shader myself. The online documentation should be updated to reflect this change.

D.