- Home /
Advice about saving complex data (Minecraft-like game)
Hey everybody. Lately, I've been writing a voxel engine for Unity, very similar to Minecraft. It's coming along very well, and I'm writing the engine separately from my game, so I will release the engine on the asset store when I feel it's ready.
I've been thinking about how I will be saving data. The world is generated pseudorandomly, meaning that the same seed will generate the same world every time. Because of this, only the blocks that are changed by the player must be saved. The world is broken up into smaller "chunks" of terrain. Like Minecraft, the world is infinite, and chunks are generated as the player explores.
Minecraft saves chunks in "regions", which are just large groups of chunks. I'm thinking that would be a good approach. Each block is stored as a byte and can be accessed via a 3 dimensional byte array. So I need to save which blocks have been changed in each chunk. But I've never had to save any custom data. I've always used playerPrefs, but I don't think that's an option here. I know you can use xml files to save some things, but I don't know much about that. I was just wondering if anyone had some good ideas? Any help would be greatfully appreciated.
A fan of voxels, wondering how your's will be different/better than those on the Asset Store now? Although this may be a discussion for another forum perhaps.
I'm making the engine VERY easy to use. Everything to get the game running will come by default. (Import the package and click "create new world". Then you can click play, and it will work). And engine settings and world data are all be changeable in the editor, without touching code. Just a few mouse clicks to add new types of blocks, and to assign textures to blocks. Custom blocks (not cube shaped) can be added just by specifying a mesh. VERY easy terrain generation, where you can create and change parameters right in the editor. There will also be the option to write your own terrain generator if the default one doesnt provide enough functionality. It will most likely be compiled into a dll, so C# or unityscript can be used. I will also include full documentation. I'm making this for a mobile game, so its optimized but no fancy graphics, sorry :/ I will release free versions as I make more progress. But the finished product may or may not be free.
you need UNity Serializer, which everyone uses. amazingly it is free. google Whydoidoit Unity Serializer
Answer by DaveA · Feb 04, 2013 at 11:33 PM
The format doesn't matter. If this is not web-based, you can use .NET file and stream classes to read/write whatever data you like (binary I would think).
Well, for each chunk that has been modified, I need an array of the changed blocks. The array will have to hold the blocks' positions and a byte for what kind of block it is. And I need very fast access to individual chunks that have been saved. It also has to be able to check if save data exists for that chunk or not. If I were to write a binary data file, how would this work?