- Home /
How to reduce lag / generation time when generating large tile maps
I am creating a game which is similar to a dungeon crawler. To do that, I started by creating a map generator. The map generator I have currently uses co-routines so I can have a loading bar, and to generate tiles it uses the Instantiate command. My problem is that at my larger map sizes (Medium - 150 x 150 tiles per floor, 5 floors, and Large, 210 X 210 tiles per floor, 7 floors) the rendering of the tiles causes drastic lag (which originally made it appear like it was frozen, now with the loading bar it does not).
For the small map it only takes about 10 seconds of generation, about 5 minutes for the medium and over an hour for the large. (Note, the large map generation is timed out by unity).
I've looked up ways to reduce the amount of time and all I've come up with are meshes. However I really don't understand meshes and so couldn't implement them even if I wanted to (at the moment anyway, I'm a fairly new programmer). As well, I am not sure I even want to use meshes since I would then have to spawn in a bunch of tiles every turn for each player, which the player would then select his/her choice and then I would remove the tiles only to repeat it a second later.
Basically I am looking for the best method to (significantly) reduce the generation time of my maps. If this is meshes, then obviously I'm going to have to learn more about meshes, but I am hopeful there is another, easier way, to do this. (Oh, and the actual time it takes to generate everything but the actual instantiation of the tiles is fairly reasonable, a couple seconds for the large. Most of the time is spent instantiating).
Thanks!
If there was a problem with your code I couldn't help without seeing your code. but my guess is your code is good! Cheers to you for your successful map generation! i dont think there is any way to get around the load time. IT IS WHAT IT IS. the CPU needs time. if you are instantiating a 210*210 amount of objects on five floor is 220500 calls of instaniate. and i'm guessing you are asking to do that in one frame:( I dont know what format you are saving in but if you cant load your big levels. keep a maximum for arrays holding info And read/instatiate sections at a time. to avoid clogging the users ram with your arrays! and you will load big levels:) you also should skip a frame between sections. unity's standard setup is single thread so it looks like an unresponsive program if you don't skip a frame here and there. as far as the time that it takes to load you just need to be creative and find a "work around". my soulution was hiding the delay behind the main menu intro. If its during play time possibly only load smaller sections at a time that are within a distance from the camera??? if you are asking for 220500 objects to be created I would hope you already have some sort of custom system/file format pry in byte arrays that only holds relevant info!
Answer by ShadyProductions · Jun 30, 2017 at 08:22 AM
You are probably creating over millions of gameobjects because you are not using meshes. If you use meshes it would only take 1 second to render maps like 750x750 http://studentgamedev.blogspot.be/2013/08/unity-voxel-tutorial-part-1-generating.html This is a great tutorial on voxel meshes the way you probably want your tilemap. It's not super difficult, you just need to get your base layer layed down.
Your answer

Follow this Question
Related Questions
Render just one object 1 Answer
Render Two texture IOS not using Blend 1 Answer
Multiple cameras, depths, and image effects! 2 Answers
find out graphic chip of Android Device 1 Answer
destroy doesn't remove the graphics 1 Answer