Dynamic World Load & Chunk Recycling

intermediate concepts

Voxel Play 4 · World Architecture

Dynamic World Load & Chunk Recycling

By default, loading a saved game brings the entire world into memory at once. For big worlds this means a longer loading screen and a lot of memory spent on places the player may never visit again.

Enable Dynamic Load changes that. You will find this option on the Voxel Play Environment inspector, inside the Save/Load System section. When enabled:

  • Regions load on demand. The savegame is stored on disk as region files (256x256 m areas). Only the regions around the player are read at start; the rest load automatically when the player gets close.
  • Saved chunks are recycled. When the player travels away, chunks whose contents are already stored in the savegame can be reused by the engine to build new terrain. If the player comes back, they are reloaded from the savegame automatically. The result: memory usage stays flat no matter how far the player explores, instead of growing with every visited area.

Your data is always safe

  • Chunks with unsaved changes are never recycled. Anything modified since the last save stays in memory until it is saved.
  • Saving never loses recycled chunks. If a region file contains chunks that are not currently in memory, saving merges them back into the file instead of overwriting them.
  • Once a modified chunk is saved it becomes recyclable again, so sessions of any length keep a stable memory footprint as long as the game saves now and then.

Requirements: a savegame backed by files on disk (a game loaded with LoadGameBinary, or any world after the first SaveGameBinary call). Worlds loaded from a byte array keep all their chunks in memory, and in server mode chunks are never recycled.

Restoring chunks from the savegame

ChunkReset accepts an optional parameter to restore a chunk to the state stored in the current savegame, instead of repainting it with the terrain generator:

// restore one chunk to its saved state (falls back to the generator if it is not in the savegame)
env.ChunkReset(chunk, restoreFromSave: true);

// restore many chunks at once; each region file is read only once
int restored = env.ChunkReset(chunkList, restoreFromSave: true);
Was this page helpful?