Infinite voxel world with cunks?

Hi everyone, I’m trying to make a minecraft game in UE4 (Just for fun) because I saw this:

Now this is what I have so far:

The problem here is I that I also want my world to be infinite and I’m already using the simplex noise bp plugin to get my Z positions values for my blocks and I also already added dirt blocks and gravel so that you can dig infinitely deep but the problem is that I generate my world with for loops and that means that it only generates a certain size that I specify, here is the code:

So you can see that the Chunk size int variable specifies how many blocks wide and long the world should be but the original minecraft works with chunks and every chunk is around 16 blocks I think and it auto generates very fast and unloads when you are far away from it and obviousely it doesn’t use for loops, otherwise it would run too slow (Like mine) So if someone can help me to show me how to get that done, I would really appreciate it. I only need to know how to generate the world in chunks and make it fast and infinite. Thats all. If I know how to do that Ill be really glad and Ill really appreciate any help to get it done and also if anyone needs my projext, Ill upload it to dropbox. feel free to ask for it anytime (-;

Hey,

the Idea with the Chunks is to sum up multiple Blocks into one 3D Array. So a Chunk is just, as you said, a 1616Z (don’t know how high a Chunk in Minecraft is) Array that holds the Data of what Block type it spawns.

So per Chunk, you have a 3D Array with Int Values, where an Int Value stands for the Block type (0 - Air, 1 - Dirt, etc).

Now you need a way to save these. Let’s say you always have 27 Chunks loaded. The one you are standing on, and the 26 around you. Imagine a Chunk is ONE big block, so you have, again, a 3D Array of Chunks that you can save.

Let’s remove the Chunks above and beneath us, so we only have plane of 9 Chunks. The one you are standing on and the 8 around you. If you move forward, you will eventually reach the Chunk in front of you, which is then the centered one. So the 3 Chunks that were behind you will be unloaded and the 3 in front of you will be loaded.

What does loading and unloading mean? Well, saving means you write the 3D Int Array into a SaveFile and loading means you read the SaveFile and iterate through the Array again.

And yes, this is done via Loops. It’s only 3 Loops iterating through the chunk Array.

Don’t use “SpawnActor” for your Blocks. You SHOULD NOT use Actors for your Blocks.

Actors are too heavy. I can’t see if you use Actors, but that’s not going to work. That would, indeed, explain why you have so long loading times. UE4, in Blueprints, has “InstancedStaticMeshs”. You will want to have one Component per Block type and spawn these based on the Int Value in the Array. They improve performance by a LOT.

Next thing you want to do to improve performance:

Only spawn visible Blocks!

Yes, why spawning blocks that have 9 blocks around them and you can’t see them anyway. When you spawn a block, check if you can actually see it (check if there is air around it or something that doesn’t block the view).

Minecraft goes even further: They only create the visible SIDES of the block. You could use the “Procedural Mesh Component” to actually only create the upper plane of a floor and not render anything beneath. That improves performance by A LOT. But, afaik, Procedural Meshs don’t have collision, so you need to at least have the chunks around you made out of Instanced Static Meshs.

Is Minecraft a good Project for Blueprints?

Well yes and no. John_Alcatraz made Minecraft in Blueprints with the Instanced Static Meshs around him and the Procedural Meshs for further away Chunks, but he eventually went to use C++.

Why? Because Minecraft is calculation heavy and Blueprints don’t offer many ways to achieve the whole Minecraft logic.

What Problems would i have with Instanced Static Meshs, since I shouldn’t spawn an Actor per Block?

Instanced Static Meshs are bound to one Material. They all share it, that’s what makes them so light-weighted.
To actually show the “Destruction” of a block, you would need to remove the InstanceStaticMesh instance and spawn a Dummy Actor at that place. If the Player stops hitting, heal the Actor back up, destroy it and spawn the Instance of the Instanced Static Mesh back.

You may see by now, that it’s a bit tricky to get Minecraft done in Blueprints. It can be done, but you need to have total knowledge about Blueprints and what they can do and how you can work around it.

Hope that helps getting started!

Cheers (: