Search Unity

Approach for Tile Engine

Discussion in 'Scripting' started by stulleman, Oct 14, 2015.

  1. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
    Hey guys,

    so I'm trying to develop a Tile "engine" for a rather long time now. It's a project I always come back to but never get further than a certain point where I loose attention because I don't like how I'm doing things.

    My current approach is one mesh (32x32 quads) per chunk. Each quad makes one tile. Tiles can be over one another (layers).
    So right now I can generate a base terrain (layer 0) and generate some vegetation above it (layer1).
    The current state would be great for a game with only 1x1 static objects in a world.
    Even the mesh generation (and terrain data generation) is multi threaded but I can't get my head around on how I would support things like:
    • tiles bigger than 1x1
    • animations
    • intractable objects like doors
    • logic objects like solar panels or ovens
    (Of course I thought about prefabs, but the main problem I see with them is when I separate it from the main mesh, it's one drawcall more per prefab)

    One of my main problem is how I would save all my data.
    Right now I use an array where each index is the id of that terrain type.
    So my map basically is just a multidimensional array with id's in it.
    An approach like that doesn't allow for further information like rotations etc.

    Of course I could just use another array, but that doesn't seem like the way to go.

    So I'm asking you guys for some advises, maybe best practices if there are any and ideas.
    Maybe I'm thinking about it too long and make it overly complicated but I'm kind of stuck right now.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    If it suits your timetable, you may want to focus on other stuff. Unity 5.4, due in March 2016, is scheduled to have a tile map engine in it with some pretty slick features (check out the Unite Boston 2015 keynote, he demos it there). I know I hate when I spend a lot of time developing something only to see an identical (or even superior) thing released for free almost immediately after I'm done, just hope to save you from that fate if you weren't aware that this is in the pipeline :)
     
  3. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
    Thank you, I didn't know that.
    I watched the keynote and indeed there are some cool features.
    But the main problem I see is that they won't help on procedural content.
    I guess behind the scenes there is not much more then a mesh as well.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I think it's too early to say whether it will have enough API access to allow for procedural content. I suspect it will, but it hasn't been stated one way or another, and admittedly Unity's new features are pretty hit or miss in that regard (hello, Shuriken). So, if procedural content is a dealbreaker, it probably is best to proceed with your own solution. Carry on!
     
  5. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
    Well, we find out when it's released.
    Aren't there unity betas with this feature yet?

    And back to topic, do you have any advice on how I would organize my items?
    What would you do to save things like terrain types, weapons, vegetation. I mean in a file (preferably json because I use that right now).
    And then how do I save my levels? Right now I just store the Tile id's in a file, but thats not enough, when I want to take into account the rotation, prefabs and some other states.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Probably won't see any of these outside Unity HQ until after 5.3 is released (December, I think)