0
votes

I'm using scaled planes to create the geometry for my level. These planes share a material, but because of the scaling, the texture on the plane is also stretched. Before switching to the lightweight render profile, I used this code to mitigate this problem:

var render = GetComponent<MeshRenderer>();
var scale = new Vector2(transform.localScale.x, transform.localScale.z);
render.material.SetTextureScale("_MainTex", scale);
render.material.SetTextureScale("_BumpMap", scale);

which created an instance of the material and changed the Tiling property to match the local scale of the object.

However, since switching to lightweight RP, the code doesn't scale the texture. When logging render.material.mainTextureScale to the debug console, it shows my updated values, but when I inspect the GameObject it is attached to, the Tiling property of the material hasn't changed.

The material uses the Lightweight Render Profile/Lit shader.

Is there any way I can fix this in my C# code? If not, is there any way to do it without changing the way I do levels?

1

1 Answers

0
votes

Yes, I discovered it is possible. I looked into the shader and the problem is that you there is no "_MainTex" map, which is what the code is looking for.

To fix it, change all instances of "_MainTex" to "_BaseMap", which is the proper map.