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

**URL:** <https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256>\
**Category:** World Creation\
**Tags:** Terrain, overlap, Instanced-Mesh, unreal-engine, Physics, Collision, generation, question\
**Created:** [April 2, 2021, 6:27am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256 "2021-04-02T06:27:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 2, 2021, 6:27am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/1 "2021-04-02T06:27:19Z")

</div>

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.

 ![334479-worldview.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/b/1cbec88a0c70931ef901a57844479f2c16ea1af9.png)

 ![334480-problem.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/a/1/2a19e7c1ef9ee805b7104898a54a528cb07bc48a.png)

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 2, 2021, 8:28am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/2 "2021-04-02T08:28:13Z")

</div>

- 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](https://answers.unrealengine.com/questions/905291/how-to-remove-specific-hism-if-colliding.html)) 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:

> **[Pyramid Construction Using Blueprints](https://forums.unrealengine.com/questions/984724/pyramid-construction-using-blueprints.html)**
>
> Hi All I have been trying to follow some tutorials on arranging an instance cube procedurally using blueprints. So far I have only managed to create the bottom 9x9 grid and I’m getting lost with how to construct the other tiers of the pyramid. I...

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 2, 2021, 10:49pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/3 "2021-04-02T22:49:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 3, 2021, 9:34am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/4 "2021-04-03T09:34:35Z")

</div>

Tracing can be done like so:

 ![334516-screenshot-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/5/d559946d4240e642a9c0da5ee34a758c3e31c9f4.png)

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

 ![334517-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/5/9/55936bd1884a7cf3d436d341d2fdea24109ced36.png)

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

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/9/6390a7c466f4551109fb73ea01b41e0299ee5e2c.gif)](https://gyazo.com/4993d451b65eb00f00943cc3c4d8bf0b)

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 3, 2021, 10:13am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/5 "2021-04-03T10:13:37Z")

</div>

> 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:

 ![334554-remove.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/e/d2e0dd579f0137862c267efcad13199856d2f442.png)

 ![334555-screenshot-6.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/6/4969d114635220d94302700f4cdbbac2c0442df3.png)

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

> **[TSet](https://docs.unrealengine.com/5.3/en-US/set-containers-in-unreal-engine/)**
>
> TSets are a fast container class to store (usually) unique elements in a context where the order is irrelevant.

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 3, 2021, 10:51am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/6 "2021-04-03T10:51:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 3, 2021, 11:42pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/7 "2021-04-03T23:42:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 4, 2021, 12:28am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/8 "2021-04-04T00:28:31Z")

</div>

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

 ![334629-image-2021-04-03-172817.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/f/b5fbcb8b6bbfbacc817019eaba7261ed33276481.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 4, 2021, 7:50am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/9 "2021-04-04T07:50:36Z")

</div>

Between second loop and add instance.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 4, 2021, 8:20am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/10 "2021-04-04T08:20:49Z")

</div>

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:

 ![334663-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/a/e3aea3bea51961d37e34b634ff1f8847c75004b1.png)

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

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/7/7c7a6bd8ebf079af9c92f126b7343a19f3152291.gif)](https://gyazo.com/419cc79a007220fcee48915e3728a1f8)

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

Good luck.

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 4, 2021, 9:49am UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/11 "2021-04-04T09:49:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 4, 2021, 11:21pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/12 "2021-04-04T23:21:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chief\_Man](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chief\_Man](https://forums.unrealengine.com/u/Chief_Man)\
**Post date:** [April 18, 2021, 9:22pm UTC](https://forums.unrealengine.com/t/how-can-i-create-a-terrain-that-forms-around-a-static-mesh-rather-than-through-it/481256/13 "2021-04-18T21:22:04Z")

</div>

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