Procedural Run-time Voxel Generation example

Hello fellow devs and creative enthusiasts!

A week or two ago on one of my streams I was tinkering with audio visualizations affecting run time environments and i wanted to procedurally create some voxel terrain as an idea for music videos etc and realized there weren’t many resources online for how to create procedural run-time voxel terrain. So i put on my thinking cap and a few hours later i had a system in place which dynamically created voxels in front of the player as they move through the world. Get ready for an image/blueprint dump! I apologize if my blueprints aren’t particularly well explained, but if you dig in you should be able to figure it out. Here is the summary of the system I used:

I procedurally created on the construction script for the player pawn a row of collision capsules some distance from the player that use the camera FOV and a render distance variable to determine their placement. I also created an actor ProceduralGeneration, which would hold the world variables for grid sizes, and spawn an initial area of chunks for the player to start in.

Collision capsules:

Player construction script:

ProceduralGeneration construction script:

Next i made an actor called ProceduralChunk which spawned 121 instances of an instanced static mesh component on construction. An array of position strings could be exposed on spawn in order to determine the height of each block, but for now i just used a random Z height so that blocks can be distinguished from each other. In this image i randomly spawned some foliage on top.

construction script of ProceduralChunk:

Next i bound an event to each of my player’s collision capsules which would fire when they were no longer colliding with worldstatic objects. (my blocks) This event would spawn a chunk at the nearest grid location to the capsule based on my chunk grid size.

Player event begin play and OverlapFailed event.

(looks like i forgot to connect up my for each break execution with the output of my UpdateHud function)

Here is the result!

If you wanted to make more realistic terrain you could drive the spawning height by overlapping perlin noise then fill in the height gaps as needed, or you could do a step function, or like minecraft does spawn all blocks down to bedrock. After 50,000+ blocks spawned my frame drops when spawning chunks would jump down to as low as 20 fps. I wasn’t handling garbage collection though and I am moving ridiculously fast. When i am not actively spawning chunks it jumps back to a steady 120fps.

Since my original intention was based on audio visualization implementation, I made some tweaks which allowed me to determine the z height of the blocks based on the low frequency spectrum waves of an audio track playing in the level. This would essentially create “hills” when the bass would hit. There are loads of things i can imagine doing with this, but here’s one example where i also randomly spawned bushes on top of blocks when the bass hit in the music. (FYI My audio driven code lost me some more fps. Honestly, it’s not the type of code i should be driving in blueprints.)

Hopefully this gives everyone some ideas and maybe some blueprint ideas if you are looking at making procedurally created voxel terrain.

Thanks for reading, and feel free to leave comments or questions!


Hey there, thanks for sharing that. Though, and i hope that is ok, i’m more interested in how you get the Audio into the Game, so you can drive things by it?
The Audio Visualization Plugin that already exists is known to be not usable, so do you use some custom plugin?

Also for the Chunks: I learned that for a good performance, one would either want to use Instance Static Meshs for blocks that the same or would only draw the faces
that are visible. So if you stay on a flat ground with 50 blocks beneath you, it’s not important to draw all the faces of these blocks if you can only see the top one you
are standing on anyway.

I mean, you just spawn an actor block for each cube, but if you ever gonna hit low fps, you know why :smiley:

PS: One of your images is not loaded!

Yes i used the audio visualization plugin. You’re right in that it is difficult to use. I ended up using the event begin play to calculate all of the spectrum data from my selected song and populating spectrum arrays. That way it isn’t actually calculated during run time, which is ridiculously inefficient based on how the plugin works.

My apologies apparently some of my images were swapped. The correct images should be there now, which will hopefully answer both those points. Each chunk is a single actor so they can be individually culled, but each block is an instance of an instanced static mesh component of the chunk.

The thing with the Visualization tool is, that they are not going to update it. The thing you see there is the endresult. At least that’s what i was told back when
i asked about it. I think it’s also not working in packaged games, but i could be wrong on that. But people told me to not use it at all and better search for
an alternative which is yet to find.

The setup with the chunk and instanced static meshs sounds good (:

Yeah the plugin really is just not… good. Once I get into learning C++ for unreal i’ll probably revisit it and try to make my own version. Here’s a sample of what i was able to generate using this method with the audio visualization plugin:

Note that i was actually getting nearly 100 fps when not doing a gif capture. Since all of the audio plugin work is done during loading the scene, the runtime information being accessed has very little tick time.

(: Looking fine. At least good enough to play around with it!

Sorry for hijacking your thread like that. Hope for more awesome stuff (:

There really isnt much about those kind of stuff made in BPs. I guess for good reasons.
I am messing around with the ProceduralMeshComponent for some days now and thought about good ways to load/unload Chunks.

Will check this out tomorrow just wanted to say thanks for sharing