Noob-question to create flexible Tilemap

Hey Guys,

I read now some hours here in the forum but i dont get answers to all my questions. So i just make an new threat and hopefully someone can help me. If there is allready somewhere a topic to this pls just post the link. Then i was just to stupid to find it.
So my questions: my plan is to make to make kind of oldschool 2D game like old zelda games for gameboy. So i wanna make a Tile map. Now i have different ideas but i dont know which is the best:

  1. I make all Tiles as graphics, put them into unity, define them as prefabs and then make a script to make a Copys from the prefabs with a Tile[,] with the coordinates for every Tile.
  2. I make an empty Tile class, intatiate them Same way with the matrix, give every empty tile an id for the tile it has to be and then i make a database with the different kinds of tiles and the tiles itself get their parameter from the database.
    (My Goal is to let it most flexible as i can… so if i want to add later new tile types it looks for me easier to just add them in the database then add them as new prefab in the game)

In the end both Ways should have the same result: a map with many tile-Objects which a can Control. But i dont know if its bad for the performance if there are that many Objects (i wanna make map of 1.000x1.000 tiles, so 1.000.000) but i think i need them as Objects because when my player Walks around i have to check the Tile where he is and if the tile is Floor or water or wall etc…
I had also the idea to make just one big map but then i dont know how i can check which tile is below him. And i had the idea to not draw and observe all objects all the time just some around the player (so like the Chunks in minecraft for examble)

So if someone can tell me which of this ideas are Maybe good or completly Trash, pls tell me. Because i am that kind of people who think first and then code and dont code and then see its trash and have to restart everyrthing again…

Yes, it’s very bad for performance to have that many objects, and is in fact impossible to instantiate a million GameObjects without crashing Unity. The standard approach is to use the Mesh class to make mesh chunks, however that still has some memory and flexibility issues when dealing with huge numbers of tiles. I took a different approach with SpriteTile, and used what you could think of as extreme frustum culling, where tiles outside the camera view are not only not rendered, but don’t even exist as GameObjects at all. Instead the existing GameObjects on screen are recycled as needed. This makes it trivial to have 1K x 1K tiles with no performance or memory issues, and can go a lot higher.

Er, sorry for the ad. :wink: Point is, no, don’t have zillions of separate objects.

–Eric

Ok, that Sounds logical. So i have to improve my knowledge about meshs. I saw once a video about it but it was for a 3d map and i thougth a 2d map dont need that stuff. Well my mistake. So thanks alot for the fast answer :smile:

This will help you with understanding meshes

I recently wrote a guide on this topic as well and I strongly advise that you give it a look. There are also links in there towards the bottom that when combined with the guide will teach you all you need to know.