- Home /
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 : https://answers.unity.com/questions/1777821/changing-hdrp-materials-texture-at-runtime-not-wor.html
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.
Answer by D_3d · Sep 15, 2021 at 11:00 AM
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.
Your answer

Follow this Question
Related Questions
Resources.Load() don't loads texture in standalone build, when in unityeditor it does 1 Answer
CustomRenderTexture (RFloat) wont initialize in the same frame it is created. 0 Answers
How to generate texture for hexagon tile? 0 Answers
Hexagonal Shape for 360 radius (painting texture) 1 Answer
Procedural planet to sphere texture 0 Answers