- Home /
How do I save my editable terrain at runtime?
In my game, you edit the terrain some but I need a way of saving these edits, but I see no feasible way of doing this. I have tried using
for ( var xnum = 0; xnum <513; xnum++)
{
for ( var ynum = 0; ynum <513; ynum++)
{
PlayerPrefs.SetFloat( "Terrain" + xnum + ynum, heights[xnum,ynum] );
}
}
but my computer is still trying to complete this action and I cant imagine that anybody wanting to play a game has the patience to wait for an hour for their terrain to save. Any suggestions? Also, in unity, if I edit the terrain in my published game, does it automatically save changes to the terrain data? Thanks!
Answer by DaveA · May 23, 2011 at 08:16 PM
That's 263169 items to save. Can Prefs handle that? In any case, it's a lot. String packing is an idea, but it would do at least as many memory reallocations, and each one takes longer than the last. Might be easier to allocate a big chunk of memory and write into it, then save that chunk. And (if not web) save using System rather than PlayerPrefs
Okay, one quick question then, how would you save using system?
$$anonymous$$any are available, for example: http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx
Sorry for all of these questions, but how would using this code work? Could you give me a small example? Also is it JavaScript compatible?
Answer by flaviusxvii · May 23, 2011 at 07:11 PM
Maybe pack all of your terrain data into one string and then save that with one call to PlayerPrefs.SetString()?
Thanks for the idea, I will try it later, the only things I could see not working is the terrain data being to long for player prefs.
Answer by logty · May 27, 2011 at 08:34 PM
I have been looking around and have tried packing all the data into one string, but that does not work either. How would I allocate a big chunk of memory to write into it? Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612083502im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SetAlphaMaps Opacity Gradient 0 Answers
How do you make the material in the Terrain detail prototype properties update after runtime? 1 Answer
How to set Flatten HeightMap in Unity 4.2 1 Answer
SetPixel() on Terrain 0 Answers
Get Terrain textures 1 Answer