Using lwrp for about 6 month. Yesterday went from 2018.3.12f1 to 2019.1.0f2, an now have an issue in changing textures on the fly, with script.
Simple thing. It was)
rend = GetComponent<MeshRenderer>();
rend.material.maintexture = newTexture;
This lines of code actually changes the texture (checked with names on maintexture) - but it is not displayed, i can see an old texture all the time.
If changed through inspector - texture changes. But it seems, that displayed texture and material.maintexture have nothing in common. Because even if we set maintexture (through script) to null - nothing changes.
If we get to standart hdrp - all is fine.
Tried getting some info through .material.shaderKeywords - no luck. Only _normalmap and _occlusionmap.
Feel, like it’s something simple, but couldn’t find the answer.
If the shader you’re using doesn’t use a texture named _MainTex as it’s main texture, it won’t work. Also, .maintexture appears to considered deprecated by Unity, though I think they keep forgetting to actually make it deprecated so people know to stop using it. It’s also entirely possible they outright broke it in 2019 as, like I mentioned, they treat it as if it’s deprecated.
This has nothing to do with material properties like textures, colors, etc. Keywords are used to pick different shader variants. Many of Unity’s shaders happen to have a keyword to enable or disable the use of normal maps which just happens to use a keyword that looks like it should be the material property name (it’s often not!). Also note that the name that appears in the inspector is just a display name and has nothing to do with the internal property name. The easiest way to know what the actual property name is would be to look at the .shader file itself. Alternatively you can use the debug inspector (right click on the inspector tab, select debug) and you can see a list of all the set properties with their actual property names.
Thanks bgolus. I was having trouble setting material texture in HDRP. And it seems main texture property is _BaseColorMap and not _BaseMap and even not _MainTex.