- Home /
How do I save and load big procedural generated terrains?
Hello, After some calculations, I discovered that a save from my game could potentially be as big as 160-200MB. That's because I'm saving the heightmaps and the other maps from a procedural generated terrain that allows editing from the player and altough the terrain is limited in size, it is still quite big.
I have already read how to use the Serializable tag to correctly save the informations I need, but accessing such a big file every time I load a game seems like a waste of resources, especially since the player would only need, say, few MBs out of it to load its position.
My question is, is there any way I can access the file at specific indexes or partition it so that I don't have to load the whole file every start of the game?
I read something about how Minecraft handles this, but it is not perfectly clear to me. Is there any C# library that allows such manipulation of files? Keep in mind that i cannot save just the seed, because the player would lose the edits he's done, and that I already have reduced all the maps and data to a bare minimum (the terrain is, as I said, pretty big, about 16kms^2)
$$anonymous$$aybe not the best solution, but I hope this can help. I believe it's intended for 2D tilemaps, but it may work for your case as well. Store tilemap data
If you are using a chunk-loading system you can do what $$anonymous$$ecraft did and write chunks on unload. You could also make a heightmap image of the terrain and/or some info about any game objects put into the terrain via an image-map or whatever. Plenty of ways without saving the actual terrain, if you are saving it of course chunk loading seems optimal because there is no way a 200mb terrain file can all be viewed at once or it is by default already too large for necessity.
Save the behind the scene info,whatever you use to generate the terrain. When you load, you feed the algorithm that creates the terrain with that info and should produce the same results. For loading chucks of the whole thing you can feed it only the coordinates you want so it won't have to reproduce all the terrain. Saving the whole thing while you have a way to reproduce it is a waste of space because you ll have to save the terrain and the info behind it, that way you keep only the info which should be extremly smaller but of course it will take a toll on the cpu while it creates the terrain.
Answer by Andros_Spica · Jun 24, 2017 at 10:53 AM
Hi @Jacho_Mendt, There is a possible solution in this tutorial by AlexStv. It allows you to save memory by serializing only the edits while rebuilding the terrain from seed I've followed the whole tutorial a year ago, so you probably won't have major problems with the current Unity version. Cheers!