Texture Tiling broken in Unity 2019.2 LWRP

I am trying to make a texture tile through a script based on my object’s scale, in Unity 2018.30f2 it works great but the same code does nothing in Unity 2019.2 using the LWRP.

As mentioned the code below works in Unity 2018.30f2 but not in Unity 2019.2 using the LWRP.
and according to the documentation, this is the way to do it?

This is my code:

cube.GetComponent<Renderer>().material.mainTextureScale = new Vector2( 1.5f, 1.5f);

This is the documentation Code:

using UnityEngine;

public class Example : MonoBehaviour
{
    Renderer rend;

    void Start()
    {
        rend = GetComponent<Renderer>();
    }

    void Update()
    {
        // Animates main texture scale in a funky way!
        float scaleX = Mathf.Cos(Time.time) * 0.5f + 1;
        float scaleY = Mathf.Sin(Time.time) * 0.5f + 1;
        rend.material.mainTextureScale = new Vector2(scaleX, scaleY);
    }
}

A bunch of the properties on materials, like .color and .mainTexture, makes assumptions about what the names of the shader properties are. mainTextureScale is implemented like this:

public Vector2 mainTextureScale
{
  get
  {
    return this.GetTextureScale("_MainTex");
  }
  set
  {
    this.SetTextureScale("_MainTex", value);
  }
}

Which breaks if the main texture is not named “_MainTex”.

I’m guessing that the default shader in LWRP doesn’t name it’s main texture “_MainTex”.

1 Like

You are 100% correct! I fixed this issue by calling “_BaseMap” as the string name of the texture instead of “_MainTex”.
Code looks like this:

 rend.material.SetTextureScale("_BaseMap", new Vector2(5,5));