Hi, I have created a procedurally generated 2D game, a little like minecraft. How would I save the changes to the world and load them in the next time you play in that world? The world is procedurally generated by the seed. Right now I can save the world but I want to be able to efficiently save the changes like mining stone and building walls.
Thanks!
I think you should not build the world from seed again, but save all objects relevant variables and properties. If your map is chunked, you can still use your seed for the not generated (and therefore untouched) chunks.
Or you split all objects in two categories:
- World objects that are fixed and not interactable (can be generated from seed again)
- World objects that can be manipulated by the player/environment (safe individually)
How would I set about checking if a item is saved already and loading it into the game?
I donât quite get, what you mean by that.
You need to load everything back into the world anyways. If you create two categories (which is probably not adviseable, if your generation algorithm is complex), then you donât âcheckâ what needs to be loaded individually and what can be generated, but you set it up yourself (meaning you split your algorithm in two parts: one for static objects and one for dynamic objects. Then you only load dynamic objects from your save/load-functions and the static ones can be generated by your map generation algorithm)
You could also implement a boolean for each object, that represents a âHasBeenManipulatedâ-state. Then you could check (but that sounds more complicated to me).
All objects must be able to be interacted with, so I canât actually split into two groups of objects unfortunately. And also only the area around the character is loaded in at a time. So objects further away are deleted.
Oh, that means you already need to save the variables and properties of manipulated objects at runtime anyways. In that case I would build a structure of tiles, that save all needed information (I donât see how you specifically do it, but your world looks like a grid to me). Whenever you load the game (or your character comes close to a tile again), you check the data in your structure and generate the stuff in that tile from there.
I was actually doing a similar thing in the past few weeks. I had a hex grid, but the idea is the same:
- Create all tiles around player in specified distance
- Save data in
Grid[X;Y].Data - If the player moves away, the objects get deleted, but the data stays alive in your structure
- If the player comes close to that tile again you check if the child
[X;Y]ofGridexists - If the child exists you load the objects based on
Grid[X;Y].Data, if it doesnât you load it based on your generation algorithm
For saving/loading the game, you just need to save/load the whole Grid-Structure.
Save/Load ALL your objects
This made me realise that id forgotten to do something in my game and thatâs save the objects that move about in the world (Irecently moved them to another array.array.structure) to storage and so anyone coming back to the game world have had a world with no aliens âŚdoh! âŚdone it now!
If youâve got the world saved in an array.array.structure or structure.array or however âŚsave it to storage when they quit and load it if it exists in storage.
then create the local area from it.
I think you should be creating the entire procedurally generated world at the start and not just the local area and so all of its there as data that you can store when they quit
I put all my aliens and humans that move in âmoveworldâ and all the scenery in ânewworldâ
Thatâs quite a good solution! However, its an infinitely procedurally generated world, does that mean my scene will have an infinite amount of tiles at the start or should I create them as I go along?
Thanks for the tips
Unfortunately, I canât create the entire procedurally generated world at the start, it is infinite.
Once youâve created it - where are you storing it? - does it just exist as objects or are you saving everything in a structure?
The seed tells the game how to generate the map tiles, any changes are saved in the âsave gameâ action, and loaded when the user loads the game.
I think youâll need to set up a structure to store everything thatâs getting generated though so that you can save everything and cull the objects that arenât local and save the changes that the player makes to the world.
You can use a grid system as spite says and store all the properties of each object along with boolean variables like âcreatedâ and âgeneratedâ (if your generating the world as the player moves through it)- for the culling algorithm. put all the objects that are getting culled in one group so that you can use repeat for each to save them in the structure. You can store a variable âtypeâ that could be the name of the object in the group.
The way i do it is quite complicated - so im not going to describe it here!
Thanks for the tips, I will try to figure it out!

