# From ProceduralMesh to DynamicMesh

**URL:** <https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, CPP, question\
**Created:** [October 3, 2022, 7:52am UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279 "2022-10-03T07:52:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![123pirke](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@123pirke](https://forums.unrealengine.com/u/123pirke)\
**Post date:** [October 3, 2022, 7:52am UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279/1 "2022-10-03T07:52:38Z")

</div>

I have a ProceduralMeshComponent which receives a simple array of vertices, indices, normals, uvs, etc. I need to update the vertex colors dynamically and my understanding is that a DynamicMesh is preffered (more efficient). So I’m converting to creating a FDynamicMesh3 instead to insert into a DynamicMeshComponent.

Instead of a single call with arrays of all the data, the only way to construct such a FDynamicMesh3 seems to be to add the vertices one by one, and then set the triangles one by one. That seems a lot less efficient with many unnecessary function calls. There also doesn’t seem to be a way to reserve memory if you know the amount of vertices and triangles up front…

Anyway, I noticed the triangles can have a group id with an undocumented AllocateTriangleGroup which simply increases an internal GroupIDCounter. What are triangle groups and when would I want to use them? Or is that similar to the ProceduralMesh having different sections where each can have a different material?

---

<div class="post-metadata">

**Author:** ![123pirke](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@123pirke](https://forums.unrealengine.com/u/123pirke)\
**Post date:** [October 3, 2022, 10:27am UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279/2 "2022-10-03T10:27:51Z")

</div>

I have the basic conversion done, but the UVs don’t seem to work… I simply provide the UV per vertex in AppendVertex with a range of 0.0-1.0, but they don’t seem to be working? I tried scaling them with a factor 10, 100 and 1000, but that didn’t seem to do anything.

Basically I do the following in BeginPlay:

FDynamicMesh3 mesh(true, true, true, false);  
Multiple calls of AppendVertex and AppendTriangle to provide all the info.  
UDynamicMeshComponent-\>GetDynamicMesh()-\>SetMesh(mesh);  
UDynamicMeshComponent-\>SetMaterial(0, Material);

I do see the shape, and in the debugger the mesh.VertexUVs is filled correctly.

Not sure what’s going on, any help is appreciated.

---

<div class="post-metadata">

**Author:** ![123pirke](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@123pirke](https://forums.unrealengine.com/u/123pirke)\
**Post date:** [October 3, 2022, 11:51am UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279/3 "2022-10-03T11:51:35Z")

</div>

After filling the FDynamicMesh3, calling

UE::Geometry::CopyVertexUVsToOverlay(mesh, \*mesh.Attributes()-\>PrimaryUV());

UE::Geometry::CopyVertexNormalsToOverlay(mesh, \*mesh.Attributes()-\>PrimaryNormals());

Seems to fix it. Not sure why this is needed.

Oh, and a copy of the VertexColors to the VertexColor overlay is also required.

---

<div class="post-metadata">

**Author:** ![olivier.perrault](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@olivier.perrault](https://forums.unrealengine.com/u/olivier.perrault)\
**Post date:** [October 12, 2023, 12:57pm UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279/4 "2023-10-12T12:57:13Z")

</div>

I am facing the same problem. Calling AppendVertex over and over seems wrong. We really should be able to reserve the number of vertices ahead of time.

---

<div class="post-metadata">

**Author:** ![LinfinityVerse](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LinfinityVerse](https://forums.unrealengine.com/u/LinfinityVerse)\
**Post date:** [February 12, 2024, 3:28pm UTC](https://forums.unrealengine.com/t/from-proceduralmesh-to-dynamicmesh/661279/5 "2024-02-12T15:28:41Z")

</div>

Internally, FDynamicMesh3 uses a bunch of rather clever containers to make user explicitly reserving buffers ahead of time unnecessary.
