r/howdidtheycodeit • u/Either_Ordinary1772 • 10h ago
Question How Do Procedurally Generated Games Save State
I was wondering how some procedurally generated games that generate the world on the fly save your progress. Specifically, how do they track where I've been as I explore the game world, what objects I've placed, what resources I harvested, and what structures have been generated. When I re-open the game later and load the world, how does it know that I placed this specific block in this specific place, and that I cut down this specific tree in this other place?
I imagine it's different based on the game, but I was curious about how it's done - does it just save everything about the generated parts of the world including what's there and what the player has done to it? Seems simple but also inefficient if the player travels through these generated sections without changing anything. Do some games just regenerate the area based on the seed but track what changes the player made to it? Are there other, more efficient ways to save this?
Here's three games that I've played that brought me to this question:
Minecraft: Minecraft generates chunks of 16x16 blocks as you explore the practically infinite world. Let's say I spawn in and build my base near the starting area, do some mining in the area, set up some farms. I then do some exploring and travel 500 blocks. I find a village there, loot some chests, and break some blocks. I travel another 500 blocks and chop down a single tree. I travel another 100 blocks and place down a crafting table, furnace, and a chest, then I place some items in said chest.
I have a feeling that Minecraft saves all the chunks I've already generated, since it takes way longer to render a chunk that has not been generated vs a chunk that was. But does it save the state of all blocks in that chunk, including the ones I placed and destroyed? Since each chunk is 16x16 blocks and if we say each chunk is about 100 blocks deep for simplicity, that's 25.6k blocks per chunk. Is all of that saved for every chunk that was generated in my journey, in addition to whatever I change? That seems like it will add up very quickly and make a massive save file.
Valheim: I'm pretty sure Valheim also generates as you explore, like Minecraft, but Valheim is not block based. Same kinda situation though, say I set up a base near the spawn, build a few buildings, sow a few carrots, and tame some boars. I then explore the world by sailing across the sea to the various boss locations. I stop in some places, cut down a tree or two to get some extra resources, loot a dungeon in the area, dig a hole, and then build a mini base and bed near the boss spawner.
The places I've been and the resources I've harvested don't regenerate or respawn as far as I am aware, so how does the game track that this specific tree has been harvested, or the resources in this specific dungeon have been looted? Or does it just save that Tree #1234 is at X, Y, Z for every single tree generated along the way?
No Man's Sky: Obviously different from the other two. I imagine it's not hard to at least store that "this star has x planets named a, b, c, and discovered by player z" in a big database. But what about when the player lands on a planet, explores some of the structures there and obtains the loot reward. Then they harvest some of the rare resources on the planet, and maybe build a small base on it. Maybe they also dig into the terrain to find a cave. How do these small things get saved such that if another player comes by and checks out the planet, will they see that someone has been there?
Not looking for a super technical explanation (though that would be cool too), just how these different games approach it at a high level. Also if there are other games that use procedural generation and have something interesting that they do, that's also welcome!

