Next up on our 2D adventure is chunking. In other words, how do we want to break apart the world?

We’re going into this with 1 assumption. To save data in the world storage arrays, we will not be adding anything to the arrays that is generated by the random world generation. This means, until the player makes edits the world will be empty, and it will allow players to assuming any missing data should be generated with world generation code vs loaded.

And one thing to note. Based on our last experiment “Can you make a 2d “voxel” world in UE5?” we determined that procedural meshes can be loaded in much faster without collision. So ideally, we will want to not use collision as much as possible to save performance.

There are 2 main approaches I will be considering.

  • Variable Chunk loading – Options 1
  • Fixed Chunk Loading – Option 2

Variable Chunk Loading

My idea of chunk loading would be variable chunk loading.

The concept is to save the data into a large database. Using data storage like a QuadTree. We would partition the data into “chunks” logically within the tree and call the data we are attempting to load. This has the benefits of more flexibility as the player can call the number of chunks they want to load, and updating the data will include just writing a new point to a quadrant of the QuadTree.

Pros: in a situation where a player needs better performance they can determine an exact number of blocks to load. We also can optionally load further out data, but it would be done sub optomally as we either load rings around the main loaded chunk, or chunks within the outer bounds.

Cons: Data is going to be more messy, the storage method will likely be much larger and harder to comb through

Fixed Chunk Loading

This is the tried and true method of generation. Minecraft does it. We just separate the world into chunks, and load chunks in based on the direction the player is looking/moving. It still offers flexibility on what is loaded, but each chunk is a set size, and that cannot be easily modified later. It would also be possible to load partial chunks, but data from the chunk would need to be filtered through to make that work.

Pros: All the data is in neat little chunks which makes working with the data a lot easier.

Cons: It’s not flexible, being unable to change chunk sizes mid game could lead to performance issues on lower end computer if loading is too demanding for the chunk size.

Winner

Fixed chunk loading.
Although I want to experiment with flexible chunk loading in the future. I would really like to try and keep difficulty designing this to a minimum, as I want to play with more complex ideas and support multiplayer. Which will require delicate chunk handling.

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *