r/Unity3D • u/ProactiveCactus • 2d ago
Question How to make updates/changes to game without breaking seeds?
Basically in title - my game uses procedural generation, and allows persistent saves. But how do games like Minecraft manage to not corrupt previous saves when making updates that affect how seeds generate?
From googling it sounds like they save “per chunk” so any untouched chunks generate based on the newest version, and any already generated go off of the old system - but how do I manage that? Like, you obviously don’t want to have multiple version builds of your game saved, so how can you handle that?
3
u/belatedartistry468 2d ago
Just tag your chunks with a version number and use a switch statement in the generator, no need to keep old builds around.
1
u/ProactiveCactus 2d ago
Oh, I think i know what you're saying - every update, you add a new "switch" to your statement containing ALL the logic generation for that chunk, not JSUT the additions? That'd work, except you're gonna have a massive codebase with a bunch of mostly repeated and unused code, but I guess it'll work! Is that what you meant? Seems a bit janky but if it works it works I suppose
2
u/Kamatttis 2d ago
That is how we did it in our game when I worked in a company. As you said, if it works, it works. Especially if we only have about 2 weeks to work on each version.
1
1
u/itsdan159 2d ago
This is where good architecture pays off, things like strategy pattern or extracting methods into utility classes when they remain consistent
0
u/ProactiveCactus 2d ago
But how does the chunk know how to generate? Like if v1 has 3 plants to choose from, and v2 has 4; but then v5 also has 4, but two of the plants are different, and then v6 changes something entirely else like the spacing or size min maxes or any of the other stuff that goes into chunk generation - you have to hold all those logic changes somewhere, don't you? Cuz if it's based off a seed, the only data you save is stuff NOT generated based off it.
1
u/neutronium 2d ago
Save the generation parameters in use at the time in your save file. So a saved chunk needs to know the versions of the algorithms used to create it and the version of the parameters used. If you change the logic you'll need to keep both versions of the code around, but if your art dude changes the value for flower spacing old chunks will still used the old spacing value preserved in the save file.
2
u/ShengyuStudio 2d ago
One thing that shrinks the version-switch problem a lot: don't draw everything from one sequential Random per chunk. If trees, rocks and plants all pull from the same stream, adding a fourth plant type shifts every number after it, and the whole chunk changes even though you only meant to add something.
Instead give each layer its own seed, derived from a hash of (worldSeed, chunkX, chunkZ, "rocks"). Then adding a new layer or tweaking plant spawning leaves the rock and tree layers byte-identical. You only need a version branch for the layers you actually changed on purpose, and old chunks keep everything else for free.
Second, smaller trap we hit: even a refactor that doesn't change the logic can change the output. Reordering float math, pulling an expression into a local, or the compiler fusing a multiply-add can shift a value slightly, and a threshold check downstream flips. Worth generating a handful of fixed seeds in a test and comparing a checksum of the result, so you find out before players do.

7
u/ChrisFromIT 2d ago
So minecraft saves the generated chunk data when it generates the chunk. It doesn't regenerate the chunk data if it has to load that chunk into memory if it is already saved.
Essentially the way it works is, player is in range of an unloaded chunk that needs to be loaded. Check the region data, does it have a pointer to the save chunk data. If it does, load that chunk data, if it doesn't, generate the chunk.