x


Saving a randomly generated Terrain

I have a randomly generated terrain and a functional Save/Load system using XML. In order to save the generated terrain, I tried serializing the heights in XML but it gives me an error (2d arrays aren't accepted as primitives). This is basically what I did :

var heights;

var xRes = Terrain.activeTerrain.terrainData.heightmapWidth;
var yRes = Terrain.activeTerrain.terrainData.heightmapHeight;
heights = Terrain.activeTerrain.terrainData.GetHeights(0, 0, xRes, yRes);

And then the data is serialized.

I tried serializing other types like int, string or even Array() and it works, so it's not the Saving system that causes the problem.

Are there any other methods to save this type of data? Would exporting the heightmap on the hard drive and importing it when loading the game work? If so, how can I export the heightmap from script?

For reference, this is the Save/Load code I'm using : http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML

Thanks for any answers.

more ▼

asked Jun 19 '10 at 05:27 PM

Jeremy 2 gravatar image

Jeremy 2
57 5 5 12

That script can't handle 2D array serialization, obviously, so you'd either need to modify the script, or write your own serialization for it.

Jun 19 '10 at 05:58 PM qJake
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
more ▼

answered Jun 19 '10 at 11:15 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1478
x438
x437
x150
x95

asked: Jun 19 '10 at 05:27 PM

Seen: 2214 times

Last Updated: Jun 19 '10 at 05:27 PM