Search Unity

Fill a large area with a tile pattern?

Discussion in '2D' started by Marscaleb, Apr 12, 2014.

Thread Status:
Not open for further replies.
  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    So I've been creating some simple levels that look like classic tile-map creations. I have square tiles I've created and I drop them into my scene like sprites and line them up.

    It works fine to create my platforms and foreground that way, since they need to be adjusted and set individually into unique patterns anyway. But there are a few spots where I want to fill a large area with a repeating pattern, like backgrounds and solid walls. If I create those using an individual sprite/game-object for each square, that will waste a lot of memory and time.

    Is there some method I can use to fill a solid area with a repeating 2D pattern?

    I *thought* I could just create a cube with a material and adjust the tiling, but for some reason when I increase the tiling of the material it gives me one little square that's the right size, and the rest of the cube face is stretched.
    I suppose I could create a cube in an 3D editor and import it, but that would be incredibly problematic to make small adjustments if it doesn't fit quite right or if I have to redesign an area.
     
  2. TIGGYsmalls

    TIGGYsmalls

    Joined:
    Jan 10, 2013
    Posts:
    38
    Have to set your texture to Texture and Wrap Mode to Repeat.
     
  3. Twinklier

    Twinklier

    Joined:
    Apr 19, 2018
    Posts:
    5
    doesn't work... I'm using a material and using it on a cube btw
     
  4. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
    You need to set wrap mode to repeat in texture import settings and in your material set tiling to number bigger than 1. Screenshot_1.png
     
    jmackenzie68 likes this.
  5. Twinklier

    Twinklier

    Joined:
    Apr 19, 2018
    Posts:
    5
    What I was thinking of is to have one single material that would repeat the texture according to the size of the object it's applied to, not multiple materials according to determined object sizes. It's pretty much either flooding my scene with cubes or flooding my asset with materials. :p

    Btw, if in case there's no other way, which is more performance-friendly? 200+ cubes or 10 materials?
     
  6. chatrat12

    chatrat12

    Joined:
    Jan 21, 2015
    Posts:
    122
    More materials = more draw calls.
    More cubes = more vertices.

    I don't know if there is any conventional wisdom here because it can really depend. In the scenario of a low end mobile device, I'd err on the side of less draw calls. GPUs push tris like no body's business.Draw calls are a CPU to GPU affair and can be taxing on slow devices.

    It's easy enough to test and get the real world data you need. Just push each method to its extreme.
     
  7. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,439
    Sounds like a job for a shader. It can calculate UVs based on world coordinates.
     
  8. Twinklier

    Twinklier

    Joined:
    Apr 19, 2018
    Posts:
    5
    Thanks a lot :) ...

    My PC seems to can't handle lots of vertices, but draw calls seems fine. Going for somewhere in between is what I'm supposed to do, I guess. Now it's getting more about performance-management, not tile materials, so I'll be outta here, but...

    Is there any chance that my game would find itself into one crappy computer that it cant keep the fps up? My PC is quite powerful so I have no clue how it would turn out on a laptop or something, unless I buy one.

    For a PC, is it fine to push the limits into vertices or shall I keep it balanced between the two? Are there anything I need to be a bit careful?

    Thanks
     
  9. UzAirMughal

    UzAirMughal

    Joined:
    Jan 28, 2018
    Posts:
    1
    will you please guide my about this i am using tilemap for first time and i am not understanding this. i also do the same thing as you did.
     
  10. Banana_Developer_101

    Banana_Developer_101

    Joined:
    Mar 27, 2020
    Posts:
    1
    i have no idea ( i have the same question )
     
  11. Yakanashe

    Yakanashe

    Joined:
    Aug 25, 2019
    Posts:
    1
    Can't you just apply a script that multiplies the tiling of the x and y to the size of the cube?
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,473
    Please look at the dates of post before posting. You're necroing an 8 year old post.
     
Thread Status:
Not open for further replies.