How can I create a terrain that forms around a static mesh, rather than through it?

I have a static mesh that looks like a pagoda. I would like to generate a 2000x2000 Minecraft style block terrain with depth (Ex: Generates 50 blocks below the surface on Y axis) that forms around my multiple randomly spawned static mesh. I would like each block of the terrain to be a separate instance so that I can destroy each individual terrain block that overlaps/collides with the static mesh. Currently, my terrain is one big piece that generates right though it, making it impossible to go down into the underground room.

The player needs to be able to drop down that hole to get down to the room, but the world terrain stops them from doing so. How can I generate my terrain so that each block is a separate instance, and so that it allows me to destroy each individual block that the static mesh collides with?

Search up the game “Trove” by Gamigo. My goal is to exactly replicate their world generation system so that I can have hundreds of different dungeons across the open world.

  • either line trace as you create the blocks, if you detect a mesh, don’t create a block there.
  • or remove a shape size block (scroll to the bottom here) after creation
  • or paint them out manually using a shape

You’ll probably end up using all 4 methods, including the noise / random generation.


Some other examples here:

Would you mind explaining how I could create the first method? That seems like a good way to remove terrain blocks when the dungeon spawns, but I am not quite sure how to do it. I am new to unreal and lack a lot of knowledge.

The second method seems okay, but I don’t want to remove instances on a ‘key pressed’ event. I would like it to happen automatically. Maybe an ‘actor begin overlap’ event would work?

I cannot do the third method because the dungeon spawn location is completely random in each chunk, and I don’t have the time to manually paint out thousands of holes into the ground. It needs to be automated to perform when the dungeon spawns.

Tracing can be done like so:

  • before we add an instance, you fire a box trace down (or any other direction that you need)

  • if trace returns True, we don’t add an instance, something was in the way

Image from Gyazo

Above, I’ve added Margin to control how closely to the shape instances are added. It can be done better, too. Treat this as a quick proof of concept, nothing else.

The second method seems okay, but I
don’t want to remove instances on a
‘key pressed’ event. I would like it
to happen automatically. Maybe an
‘actor begin overlap’ event would
work?

Run the generation first and once it’s complete:

The above is a gross oversimplification, of course. And you can read up on how sets work in UE4 here:

I will try both of these out tomorrow. It is 4am here and I am going to bed soon. This is exactly the kind of thing I have been trying to figure out the past few days. Thanks for the help!

I cannot figure out where I am supposed to add in the linetrace construction script.

Here is my current world terrain generation construction script. Do I add in the line trace somewhere here?

Between second loop and add instance.

I’ll just add that the process can be inverted or used in addition to removal. You can have block position conform to other shapes:

Here, rather than removed, they end up placed on top of the shape:

Image from Gyazo

Sides can be filled in by tracing from more than 1 direction.

Good luck.

I added it to my construction script and the whole terrain disappears. I think my terrain is being counted as one big piece rather than each individual block being its own instance. I setup my terrain to generate the 1m_cube as a hierarchical instanced static mesh. Do you know how I can set it up so that each block is a separate instance from the others that form the terrain?

The script makes my whole terrain disappear even if the terrain doesn’t collide with anything

I still haven’t been able to figure out how to get this to work :frowning: