Can't seem to make tiling change through script with HDRP Shaders

using UnityEngine;
using System.Collections;

// Tile each material according to the object's scale.
// Author: Lucas A. Mello

[ExecuteInEditMode]
public class TileTexture : MonoBehaviour
{
    void Update()
    {
        // Get scales
        float x = transform.localScale.x;
        float y = transform.localScale.y;
        float z = transform.localScale.z;
        float max = x > y ? x : y;
        max = max > z ? max : z;
       
        // Get the mesh
        Mesh theMesh;
        theMesh = this.transform.GetComponent<MeshFilter>().sharedMesh as Mesh;
   
        // Now store a local reference for the UVs
        Vector2[] theUVs = new Vector2[theMesh.uv.Length];
        theUVs = theMesh.uv;
       
        // Vertices order:
        //    2    3    0    1   z+
        //    6    7   10   11   z-
        //   19   17   16   18   x-
        //   23   21   20   22   x+
        //    4    5    8    9   Top
        //   15   13   12   14   Bottom
   
        // set UV co-ordinates
        theUVs[2] = new Vector2(0f, y/max);
        theUVs[3] = new Vector2(x/max, y/max);
        theUVs[0] = new Vector2(0f, 0f);
        theUVs[1] = new Vector2(x/max, 0f);
       
        theUVs[11] = new Vector2(0f, y/max);
        theUVs[10] = new Vector2(x/max, y/max);
        theUVs[7] = new Vector2(0f, 0f);
        theUVs[6] = new Vector2(x/max, 0f);
       
        theUVs[19] = new Vector2(0f, y/max);
        theUVs[17] = new Vector2(z/max, y/max);
        theUVs[16] = new Vector2(0f, 0f);
        theUVs[18] = new Vector2(z/max, 0f);
       
        theUVs[23] = new Vector2(0f, y/max);
        theUVs[21] = new Vector2(z/max, y/max);
        theUVs[20] = new Vector2(0f, 0f);
        theUVs[22] = new Vector2(z/max, 0f);
       
        theUVs[4] = new Vector2(0f, z/max);
        theUVs[5] = new Vector2(x/max, z/max);
        theUVs[8] = new Vector2(0f, 0f);
        theUVs[9] = new Vector2(x/max, 0f);
       
        theUVs[15] = new Vector2(0f, 0f);
        theUVs[13] = new Vector2(0f, 0f);
        theUVs[12] = new Vector2(0f, 0f);
        theUVs[14] = new Vector2(0f, 0f);       
   
        // Assign the mesh its new UVs
        theMesh.uv = theUVs;
       
        GetComponent<Renderer>().sharedMaterial.SetTextureScale("_MainTex", new Vector2(max/2f, max/2f));
    }
   
}

Script above not mine, just changed a little.

I’m trying to get a auto-tiling like thing to work in my scene, but it does seems to not change the values of tiling when used in hdrp, altought it works in the standard unity. I’ve searched everywhere but there is no thread talking about it, i’ve tried lots of things and can’t seem to make it work

Hi,
Welcome to the club, you probably have to do the same as everyone else at the moment and go check the HDRP source code that is available in the package folder. Many things have changed and old names will not work.

Try this:

material.SetTextureScale("_BaseColorMap", tiling);

And you should get access to the tiling, at least if you use the HDRP/Lit material.

2 Likes

@Olmi I’ve tried that, but it messes up my UV mapping for some reason that I haven’t figured out yet.

@SeveQStorm probably another issue with your model, but that setting does change texture tiling in a material. Got any images to show?

Maybe You meant offset?

material.SetTextureOffset(“_BaseColorMap”, material.GetTextureOffset(“_BaseColorMap”) + new Vector2(offsetXEveryFrame, offsetYEveryFrame));