How to save arrays to a file.

I’m trying to save a world to a file by getting each chunk and saving their atlas maps and height maps to a file, I can save atlas maps fine as a .png but i am unable to figure out have to save and load an array of floats how can achieve this, Thanks.

Also a note to consider that is that these chunks height maps array size are going to be quite big so i would prefer to load all the heights from a saved file instantly into a array if that’s possible.

I would suggest you to use JSON to save your files with. You could of course use a simpler way and just save your floats seperated with a char (e.g. :wink: as plain text into a file and on loading it simply split it with that char again. But it might be a cleaner solution to work with json here.

Simple File Save for example:

string lines = "20.39;23.1;229.2";

System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);

file.Close();

And here are some links to read to get you started:

(Maybe an alternative in unity: Unity - Manual: Text assets)

It’s far, far more efficient just to save the bytes. Generally stay away from trying to parse floats as text for various reasons (regional differences etc.).

–Eric