# Generate Procedural Mesh

**URL:** <https://forums.unrealengine.com/t/generate-procedural-mesh/1393>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 30, 2014, 5:34am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393 "2014-03-30T05:34:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 5:34am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/1 "2014-03-30T05:34:58Z")

</div>

Anyone know how to make a mesh from vertices and triangles, attach it to an object and spawn it?

I looked into FDynamicMeshBuilder, but that’s only for drawing.

---

<div class="post-metadata">

**Author:** ![FireOnHigh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FireOnHigh](https://forums.unrealengine.com/u/FireOnHigh)\
**Post date:** [March 30, 2014, 6:58am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/2 "2014-03-30T06:58:55Z")

</div>

There is a CustomMeshComponent, and you fill it with a CustomMeshTriangle array. I have had no luck finding a way to properly apply materials to these however (unless its just a base color).

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [March 30, 2014, 8:26am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/3 "2014-03-30T08:26:41Z")

</div>

CustomMeshComponent derives from MeshComponent, which has a Materials array and a SetMaterial function, that should work. CustomMeshComponent currently only have a single material section. Note that CMC is really an example of how to create your own geometry, you may want to create your own component class so you can get full control over UVs, tangents, sections etc.

---

<div class="post-metadata">

**Author:** ![FireOnHigh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FireOnHigh](https://forums.unrealengine.com/u/FireOnHigh)\
**Post date:** [March 30, 2014, 9:45am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/4 "2014-03-30T09:45:04Z")

</div>

Thanks for clarifying . I had only recently found the CMC and had only tinkered around with it in blueprints. Nice to get confirmation on it’s intended purpose.

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [March 30, 2014, 10:21am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/5 "2014-03-30T10:21:14Z")

</div>

I would actually like to do a bit more work on it and allow BP authors to specify more geometry information . I love the idea of procedural geometry 😃

---

<div class="post-metadata">

**Author:** ![phoboz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phoboz](https://forums.unrealengine.com/u/phoboz)\
**Post date:** [March 30, 2014, 12:31pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/6 "2014-03-30T12:31:28Z")

</div>

Is there a performance hit when using dynamically created geometry rather than regular static mesh?

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 2:23pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/7 "2014-03-30T14:23:00Z")

</div>

Thanks for the feedback. Can anyone share a bit of code that shows object creation, CustomMeshComponent attach, vertex and triangle assignment, and then spawn?

---

<div class="post-metadata">

**Author:** ![Daydreamer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Daydreamer](https://forums.unrealengine.com/u/Daydreamer)\
**Post date:** [March 30, 2014, 3:32pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/8 "2014-03-30T15:32:36Z")

</div>

[=JamesG;8919]  
I would actually like to do a bit more work on it and allow BP authors to specify more geometry information . I love the idea of procedural geometry 😃  
[/]

I suspect many of us developers love the idea of procedural geometry as well. Looking forward to what you come up with!

---

<div class="post-metadata">

**Author:** ![vblanco](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vblanco](https://forums.unrealengine.com/u/vblanco)\
**Post date:** [March 30, 2014, 5:15pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/9 "2014-03-30T17:15:47Z")

</div>

Ill see if i can find some time, and port my voxel engine code to a custom mesh ( total \*\*\*\*, but creates the cube meshes from 3 dimensional array), and make a tutorial of it.

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 5:53pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/10 "2014-03-30T17:53:03Z")

</div>

[=anonymous\_user\_e71e0d8ablanco;9085]  
Ill see if i can find some time, and port my voxel engine code to a custom mesh ( total \*\*\*\*, but creates the cube meshes from 3 dimensional array), and make a tutorial of it.  
[/]

That would be awesome. In the meantime I’ve hit a snag if anyone know a quick solution. I’ve created an Actor class setting a UCustomMeshComponent as RootComponent, but I am getting link errors:

```auto

1>------ Build started: Project: MyProject5, Configuration: Development_Editor x64 ------
1> Parsing headers for MyProject5Editor
1> Code generation finished for MyProject5Editor and took 1.71
1> link.exe UE4Editor-MyProject5.dll
1> Creating library C:\dev\Unreal\Projects\MyProject5\Intermediate\Build\Win64\MyProject5Editor\Development\UE4Editor-MyProject5.lib and object C:\dev\Unreal\Projects\MyProject5\Intermediate\Build\Win64\MyProject5Editor\Development\UE4Editor-MyProject5.exp
1>GameGeneratedActor.cpp.obj : error LNK2019: unresolved external symbol "private: static class UClass * __cdecl UCustomMeshComponent::GetPrivateStaticClass(wchar_t const *)" (?GetPrivateStaticClass@UCustomMeshComponent@@CAPEAVUClass@@PEB_W@Z) referenced in function "public: class UCustomMeshComponent *__cdecl FPostConstructInitializeProperties::CreateDefaultSubobject<class UCustomMeshComponent,class UCustomMeshComponent>(class UObject *,class FName,bool,bool,bool)const " (??$CreateDefaultSubobject@VUCustomMeshComponent@@V1@@FPostConstructInitializeProperties@@QEBAPEAVUCustomMeshComponent@@PEAVUObject@@VFName@@_N22@Z)
1>GameGeneratedActor.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl UCustomMeshComponent::SetCustomMeshTriangles(class TArray<struct FCustomMeshTriangle,class FDefaultAllocator> const &)" (?SetCustomMeshTriangles@UCustomMeshComponent@@QEAA_NAEBV?$TArray@UFCustomMeshTriangle@@VFDefaultAllocator@@@@@Z) referenced in function "public:__cdecl AGameGeneratedActor::AGameGeneratedActor(class FPostConstructInitializeProperties const &)" (??0AGameGeneratedActor@@QEAA@AEBVFPostConstructInitializeProperties@@@Z)
1>C:\dev\Unreal\Projects\MyProject5\Binaries\Win64\UE4Editor-MyProject5.dll : fatal error LNK1120: 2 unresolved externals
1> -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\dev\Unreal\Projects\MyProject5\Binaries\Win64\UE4Editor-MyProject5.dll
1> Cumulative action seconds (8 processors): 0.00 building projects, 0.00 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.10 linking, 0.00 other
1> UBT execution time: 4.27 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Unreal Engine\4.0\Engine\Build\BatchFiles\Build.bat" MyProject5Editor Win64 Development "C:\dev\Unreal\Projects\MyProject5\MyProject5.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

```

This is my Build.cs setup, what am I missing?

```auto

using UnrealBuildTool;

public class MyProject5 : ModuleRules
{
	public MyProject5(TargetInfo Target)
	{
		PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

                PrivateDependencyModuleNames.AddRange(new string] { "CustomMeshComponent" });
                PrivateIncludePathModuleNames.AddRange(new string] { "CustomMeshComponent" });

                MinFilesUsingPrecompiledHeaderOverride = 1;
                bFasterWithoutUnity = true;

	}
}

```

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 6:23pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/11 "2014-03-30T18:23:15Z")

</div>

As a workaround, I re-implemented CustomMeshComponent in the project and had to add RHI, RenderCore and ShaderCore as dependencies, and it compiled. And now to see if this works…

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 6:33pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/12 "2014-03-30T18:33:21Z")

</div>

Tadaa, from a simple lathe routine:

[![](https://content.screencast.com/users/Andargor/folders/Jing/media/ede3a62c-0e07-44b4-b089-b956d870b4b3/example2.jpg) ](https://content.screencast.com/users/Andargor/folders/Jing/media/ede3a62c-0e07-44b4-b089-b956d870b4b3/example2.jpg)

I just uses my HUD blueprint to call SpawnActor and specify my class. Now to continue my experiments…

---

<div class="post-metadata">

**Author:** ![vblanco](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vblanco](https://forums.unrealengine.com/u/vblanco)\
**Post date:** [March 30, 2014, 6:40pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/13 "2014-03-30T18:40:59Z")

</div>

Impressive work, man. Will you make a tutorial on how to set that up?

---

<div class="post-metadata">

**Author:** ![Daerst](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daerst/32/266918_2.png) [@Daerst](https://forums.unrealengine.com/u/Daerst)\
**Post date:** [March 30, 2014, 6:43pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/14 "2014-03-30T18:43:54Z")

</div>

[=vblanco;9134]  
Impressive work, man. Will you make a tutorial on how to set that up?  
[/]

_looking at the picture_ … Only coders will understand! 😃

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 7:26pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/15 "2014-03-30T19:26:03Z")

</div>

[=vblanco;9134]  
Impressive work, man. Will you make a tutorial on how to set that up?  
[/]

Aha! You guys didn’t notice my normals were inverted… (Unreal seems to like clockwise vertices) I will share my code on the wiki to get you started with quick and dirty instructions, although it will not be to -sama standards 😉 I’ll post here when it’s up.

Here’s another with more segments and proper normals:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/8/cf805257068b49d81b3b81b5413ea31799624dfb.jpeg) ](https://cdn.screencast.com/uploads/g000302qWkAIKELODn94yoNMCC30l/example1.jpg?sv=2021-08-06&st=2023-04-26T04%3A10%3A10Z&se=2023-04-27T04%3A10%3A10Z&sr=b&sp=r&sig=rUzeX25hBS74dKRMQixj5yyku9Jzal710UCI08aCTVQ%3D)

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [March 30, 2014, 8:10pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/16 "2014-03-30T20:10:38Z")

</div>

Here’s the example. [A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums](https://wiki.unrealengine.com/Procedural_Mesh_Generation)

I haven’t been able to embed images (I’m a wiki noob and short on time), but there are links. Here’s what the blueprint portion looks like, really standard and simple:

[![](https://content.screencast.com/users/Andargor/folders/Jing/media/58f259a9-8b91-4a4f-a0e6-a8fc437cdf81/example3.jpg) ](https://content.screencast.com/users/Andargor/folders/Jing/media/58f259a9-8b91-4a4f-a0e6-a8fc437cdf81/example3.jpg)

---

<div class="post-metadata">

**Author:** ![vblanco](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vblanco](https://forums.unrealengine.com/u/vblanco)\
**Post date:** [March 30, 2014, 8:47pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/17 "2014-03-30T20:47:42Z")

</div>

very cool, ill see if i can make my voxel chunk object like that.

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [March 31, 2014, 3:32pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/18 "2014-03-31T15:32:21Z")

</div>

[=;8972]  
Is there a performance hit when using dynamically created geometry rather than regular static mesh?  
[/]

Right now this geometry is slightly slower than a regular static mesh, and doesn’t support things like precomputed lighting.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 1, 2014, 2:04am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/19 "2014-04-01T02:04:43Z")

</div>

[=dmacesic;9160]  
Aha! You guys didn’t notice my normals were inverted… (Unreal seems to like clockwise vertices) I will share my code on the wiki to get you started with quick and dirty instructions, although it will not be to-sama standards 😉 I’ll post here when it’s up.

Here’s another with more segments and proper normals:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/1/8b168e2a28efa8f02c8ba0bccd43e7d6c716b085.png) ](https://cdn.screencast.com/uploads/g000302YWBLK1wJxsg7PGi7nUBA5s/2014-03-30_1523.png?sv=2021-08-06&st=2023-04-26T04%3A10%3A10Z&se=2023-04-27T04%3A10%3A10Z&sr=b&sp=r&sig=xM0ck2HqVc%2FeChOBo9FC4suWCVRHqGXvlgnstjiOBms%3D)

[/]

Wow this is awesome!

Amazing work Dmacesic!

Please do share the tutorial!

Amazing things will come of it!

EDIT

His tutorial is now up and available here!

**Procedural Mesh**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

🙂

---

<div class="post-metadata">

**Author:** ![Andargor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andargor](https://forums.unrealengine.com/u/Andargor)\
**Post date:** [April 1, 2014, 3:43am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/20 "2014-04-01T03:43:02Z")

</div>

🆒

I thought I had published that yesterday, did you do anything to make it public?

[Next page](https://forums.unrealengine.com/t/generate-procedural-mesh/1393.md?page=2)
