Search Unity

Repeating texture without stretching

Discussion in 'General Graphics' started by n4005, Jan 20, 2020.

  1. n4005

    n4005

    Joined:
    Jan 17, 2020
    Posts:
    4
    I'm pretty new to Unity and I want to make different sized ground blocks which have a material texture attached to them. Is it possible to make Unity automatically repeat the texture on different sized blocks so I wouldn't have to set the tiling X and Y for each block manually? What kind of components and shaders should I use?
     
  2. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    There are two options here:
    - Adjust the uv maps of the objects to reflect the tiling you want to achieve. Let's say your block is 1x1, than your uv coordinates should range from (0,0) in one corner to (1,1) in the opposite one. If your block is 2x2, your uv coordinates should range from (0,0) to (2,2)
    - You could go for a custom shader solution based on the world space coordinates of your vertices instead of uv coordinates (if your boxes are axis aligned), alternatively you could use the vertex coordinates in object space but this requires the proper setup when modelling the blocks as well
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Another option is to use ProBuilder, available in the package manager. That lets you create geometry in Unity and automatically tiles textures by the world space size of each face.
     
  4. n4005

    n4005

    Joined:
    Jan 17, 2020
    Posts:
    4
    Thanks for the replies! I'll try to make it work :)
     
  5. bdilloughery_mvla

    bdilloughery_mvla

    Joined:
    Sep 22, 2017
    Posts:
    39
    Just to echo bgolus, if you create a new shape in ProBuilder, you can edit it's shape and size before clicking the build button. In that way you could create your walls of any size and they would still be at a scale of 1:1:1, allowing you to use that one material on all objects.