Generate Procedural Mesh

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.

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).

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.

Thanks for clarifying James. 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.

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

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

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

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

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:

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?

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;


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…

Tadaa, from a simple lathe routine:

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

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

looking at the picture … Only coders will understand! :smiley:

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 Rama-sama standards :wink: I’ll post here when it’s up.

Here’s another with more segments and proper normals:

Here’s the example. A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

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:

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

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

Wow this is awesome!

Amazing work Dmacesic!

Please do share the tutorial!

Amazing things will come of it!


His tutorial is now up and available here!

Procedural Mesh




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