- Home /
How to display a tile map efficiently?
Hello everyone,
I have a pretty general question. I'm wondering what the most efficient way in Unity would be to display a tile map. I'm writing an online game and in my case, the client gets the tile data from the server after login, and then instantiates tiles based on that data.
I am aiming for a view distance of 500 tiles in any direction, so 1001x1001 concurrent tiles, over 1 million in total. Each tile has 4 vertices.
So I figured it would be better to make the tiles part of the scene and move them to wherever I want after the login and assign a material, instead of instantiating them by code. But even instantiating 20,000 tiles takes forever, and the Unity Editor is practically not responsive after I do that.
Does anyone have any hints how I should go about this?
Thanks for your help.
Do you actually need 500 tiles visible in any direction? They'd only be a few pixels big.
I'm not really sure yet. $$anonymous$$aybe I'll only need 300 or 400 in the end, but I don't know that yet. The tiles also differ in height. There'll be mountains that should be visible over such a distance.
Answer by Loius · Nov 13, 2013 at 07:03 AM
You can't have that many objects - you need to build them in chunks. Make a 50x50 mesh, copy-paste it as necessary. You can build meshes at runtime or just assign their uvs at runtime, but Unity just can't handle 20,000 objects being created at once.
Hmm that's kind of unfortunate, but good to know at least. If I was making 50x50 chunks, how would I apply different textures to each tile though? Wouldn't I need to create a texture for the whole chunk at runtime, since I don't know before I log in which of those tiles are dirt and grass etc?
I suppose this is where submeshes come into play? Can anyone point me to a submeshes tutorial maybe? I really can't find one.
EDIT: Never$$anonymous$$d, the accepted answer to this link cleared things up for me: http://answers.unity3d.com/questions/312492/submesh-creation-from-script.html
I'll try to make chunks with submeshes.
Well, I did end up doing that. I can make chunks now. But the texture problem isn't solved. Is it even possible to assign different materials to submeshes?
You don't happen to have any tutorial on how to do that?
I set the number of submeshes and assigned the triangles to each submesh. But the mesh class doesn't have any method like getSub$$anonymous$$esh or anything. I'm confused.
Your answer
Follow this Question
Related Questions
Question regarding TileMap Performance 0 Answers
Dynamically add tiles from strings using C# 0 Answers
How to create tile prefabs? 1 Answer
Issue I'm having with Rule Tiles, anyone able to solve this? 1 Answer
Tiles with their own scripts 1 Answer