Hi there, I’m trying to access the floor texture of a HDRP/Lit shader material in code using renderer.material.GetTexture(“_MainTex”). I’ve also tried renderer.sharedMaterial.GetTexture(“_MainTex”).
Looking at the material in debug mode within the inspector, I can see the reference ‘_MainTex’, but for whatever reason it can never find it. In sheer desperation I’ve also tried numerous other names such as MainTex,mainTexture, BaseColorMap etc but everything fails.
I also read a post suggesting that you need to enable read/write on the texture, but again this hasn’t helped. Any help, much appreciated!
The texture you are looking for is named “_BaseColorMap”.
See the shader source code here for properties reference.
Appreciate the response, but it’s a case of 2 steps forward…
So the following line of code:
Texture tex = renderer.material.GetTexture("_BaseColorMap");
…is returning the texture Gridbox_Default which is correct. I’m then trying to compare that texture against one referenced in the inspector (this is a footstep system):
if (gr.albedo.Equals( tex ) )
{
// They match!
}else{
// They don't!!
}
gr.albedo also has a refence to Gridbox_Default, yet the above statement is always false - Unity doesn’t think it’s the same texture (it is!). Any further suggestions?
Thanks for any help!