Search Unity

Top Down Tile Maps Combine Children

Discussion in 'Scripting' started by smarcus, Feb 28, 2008.

  1. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    OK, so I am throwing together a flat terrain (for a top-down view) made out of square tiles (it is not the most innovative thing since sliced bread... actually, you could probably do the same thing with sliced bread).

    Anyway, it's easy enough to make a plane and slap a texture on it and splotch them together until a parent game object... the question is, is it worth attaching the Combine Children script to the parent? Alternatively- is there any downside?

    I imagine there will be a fair number of materials involved, and Combine Children will create a separate mesh for each. If I end up with a series of textures mapped on a bunch of wonky discontiguous meshes like so:

    Code (csharp):
    1.  
    2. 111233212     111    1           2  2 2           33  
    3. 123321223     1    1           2  2 22          33    3
    4. 233122312  =     1   1    +   2   22  2   +    33   3  
    5. 331111233       1111                2         33     33
    6. 222322211            11       222 222            3    
    7.  
    So... I guess rendering fewer meshes will always/usually be better, but are there other problems I might run into with these interlaced meshes? Inconsistent mesh collision behavior? Seam issues? What should I be on the lookout for?

    Er... for what should I be on the lookout?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Probably. I didn't bother when I did this, but the shader was really basic and the tiles were pretty large, so I was getting 500fps anyway. With more detail and more tiles, you'd see more benefit I suspect.

    Nothing that I can think of, offhand.

    Your first sentence was correct. ;) Let us band together and destroy the annoyingly persistent myth that "you can't end a sentence with a preposition", since that's a wholly invented "rule" dreamt up by someone with no life, which doesn't apply to English....

    --Eric
     
  3. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    I dunno, man... sure- we start ending sentences with prepositions and life seems ok- for a bit, maybe- but where does it stop? Next we'll trade all our whom's in for who, and by the time we abandon the subjunctive 'were' for 'was'- well, by then it will be too late. We'll wake up one day and find that by degrees we've lost ahold of our language and kids are finishing sentences off with dangling articles and conjunctions. As society collapses the streets will fill with aimless drifters who practice semicolonry, indiscriminately assigning punctuation marks to the spaces between words because by now they're little more than animals don't know any better. Run-on sentences, come alive through dark, hideous magycks unleashed by mad grammarians, will rampage through our cities, drowning the few who remain in clauses, phrases, and more conjunctions (but they won't end sentences with them).
     
  4. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    Have you considered using the GUI system for this? If the game is 2D that might be a reasonable way to go. The next best would be to create a mesh using the Mesh class that shares one texture containing all the tiles.

    You can look up stuff like this in the documentation and wiki. I think there might be a frame based uv animation script on the wiki that would be similar to what you would use for making a tile map.
     
  5. smarcus

    smarcus

    Joined:
    Sep 18, 2007
    Posts:
    113
    I should have clarified better- it's not strict 2D tile map. I want to make an island, and I plan to have basically 3 elevations- land (with a y of 1, say), seafloor (y of 0), and transition (slanted tiles that will join the two...) and then a water plane at y=0.5 (I am making these values up).

    But it dawned on me once I got the CombineChildren component set up and working that I want to make some of the terrain tiles mutable, which I think means that I will probably want them to be individual objects- because it's much easier to change one tile's material than to compose a one-tile change on a terrain-wide material and update a larger mesh, yes?
     
  6. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Generally, you want to use as few objects as possible. So best is always to create one object that uses one material, as this will result in the shortest time spent rendering the scene.

    In the case that you want to create levels through a script-driven system, Combine Children would be just fine. You want to optimize the mesh of course, so you should use two-triangle planes instead of Unity's built-in planes for the final product.

    If you have three different kinds of images you want to use for each tile, put the three images in one image file. This way, all the tiles would become one object, which is better than three objects. But depending on what you want to do with the game, maybe you want three objects. It's really just depending on what you require from this part of your game.