# 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:** 3

<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:** [May 12, 2014, 10:05am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/42 "2014-05-12T10:05:28Z")

</div>

[=ACCA software S.p.A.;40176]  
Is there a way to create multiple instances of the same CustomMeshComponent? Like InstancedStaticMeshComponent?  
[/]

No, you would just need to add multiple components. Or create your own InstancedCustomMeshComponent 🙂

---

<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:** [May 12, 2014, 11:41pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/43 "2014-05-12T23:41:35Z")

</div>

, any hints on the best way to use procedural meshes with SkeletalMeshActors? I noticed you can either have SkeletalMeshComponents (that wrap SkeletalMeshes), or have any AActor derived class attach to a socket. Would the latter be a way of allowing procedural meshes to be connected to a skeletal mesh?

---

<div class="post-metadata">

**Author:** ![Mowfax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mowfax](https://forums.unrealengine.com/u/Mowfax)\
**Post date:** [May 13, 2014, 11:54pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/44 "2014-05-13T23:54:15Z")

</div>

First up, I’m no C++ programmer but if I have no other way, I have to finally learn some… So here’s my question.  
If I want to have a deformable Landscape in my game (think worms or scorched earth), would I need what is talked about here or is there an easier way in UE4?

---

<div class="post-metadata">

**Author:** ![ACCA\_software\_S.p.A](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ACCA\_software\_S.p.A](https://forums.unrealengine.com/u/ACCA_software_S.p.A)\
**Post date:** [May 14, 2014, 4:28pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/45 "2014-05-14T16:28:18Z")

</div>

[=JamesG;40270]  
No, you would just need to add multiple components. Or create your own InstancedCustomMeshComponent 🙂  
[/]

Thanks for the reply.

On the other hand, is it possible to create a procedural StaticMesh at runtime? Can we use RawMesh?

Thanks.

---

<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:** [May 14, 2014, 7:40pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/46 "2014-05-14T19:40:03Z")

</div>

[=ACCA software S.p.A.;44991]  
Thanks for the reply.

On the other hand, is it possible to create a procedural StaticMesh at runtime? Can we use RawMesh?

Thanks.  
[/]

Yes you can, that’s what most of these procedural mesh discussions have accomplished so far 🙂

Here’s a pic of my own procedural mesh, made at runtime and uv-mapped via algorithm!

Notice that it has collision!

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/f/97fbf34c477be009a1e65c9ecc60fd5172a56358.jpeg)

---

<div class="post-metadata">

**Author:** ![ACCA\_software\_S.p.A](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ACCA\_software\_S.p.A](https://forums.unrealengine.com/u/ACCA_software_S.p.A)\
**Post date:** [May 15, 2014, 10:46am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/47 "2014-05-15T10:46:05Z")

</div>

[=;45355]  
Yes you can, that’s what most of these procedural mesh discussions have accomplished so far 🙂

Here’s a pic of my own procedural mesh, made at runtime and uv-mapped via algorithm!

Notice that it has collision!

[/]

Your procedural mesh, if I’m not mistaken, was created with UCustomMeshComponent.  
What I mean to do is a procedural creation of an UStaticMesh and assign it to an UStaticMeshComponent because, from what I have understood, UStaticMesh supports precomputed lighting, mesh Instancing and has better performance. Am I right?

---

<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:** [May 15, 2014, 2:59pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/48 "2014-05-15T14:59:40Z")

</div>

[=ACCA software S.p.A.;46449]  
Your procedural mesh, if I’m not mistaken, was created with UCustomMeshComponent.  
What I mean to do is a procedural creation of an UStaticMesh and assign it to an UStaticMeshComponent because, from what I have understood, UStaticMesh supports precomputed lighting, mesh Instancing and has better performance. Am I right?  
[/]

From what I understand, UStaticMesh requires an asset, so by definition it cannot be procedurally generated. You could generate an asset and save it (to be able to load), however. Not sure if you would need to reverse engineer how assets are created or reuse and ship some of the UEd code to import assets (there may be legal issues here).

---

<div class="post-metadata">

**Author:** ![SamH](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SamH](https://forums.unrealengine.com/u/SamH)\
**Post date:** [May 15, 2014, 9:32pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/49 "2014-05-15T21:32:28Z")

</div>

Has anyone been able to get vertex colours working with this?

I’ve tried setting the Color variable for each vertex before it’s added to the buffer (while using a VertexColor node in the material), but it doesn’t seem to have any effect.

---

<div class="post-metadata">

**Author:** ![Ryvar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ryvar](https://forums.unrealengine.com/u/Ryvar)\
**Post date:** [May 18, 2014, 3:20am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/52 "2014-05-18T03:20:34Z")

</div>

re: Vertex Color - make sure you include the underlined line in your VertexFactory, or the color data will never get copied:

```auto

			ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
				InitChunkVertexFactory,
				FChunkVertexFactory*, VertexFactory, this,
				const FChunkVertexBuffer*, VertexBuffer, VertexBuffer,
				{
				DataType NewData;
				NewData.PositionComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, Position, VET_Float3);
				NewData.TextureCoordinates.Add(FVertexStreamComponent(VertexBuffer, STRUCT_OFFSET(FDynamicMeshVertex, TextureCoordinate), sizeof(FDynamicMeshVertex), VET_Float2));
				NewData.TangentBasisComponents[0] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, TangentX, VET_PackedNormal);
				NewData.TangentBasisComponents[1] = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, TangentZ, VET_PackedNormal);
**NewData.ColorComponent = STRUCTMEMBER_VERTEXSTREAMCOMPONENT(VertexBuffer, FDynamicMeshVertex, Color, VET_Color);**
				VertexFactory->SetData(NewData);
			});

```

Check LocalVertexFactory.h for more info.

---

<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:** [May 19, 2014, 9:06am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/53 "2014-05-19T09:06:32Z")

</div>

[=Ryvar;50833]  
re: Vertex Color - make sure you include the underlined line in your VertexFactory, or the color data will never get copied:  
[/]

Ah good catch, I’ll make that fix in the code now. Thanks!

---

<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:** [May 19, 2014, 6:37pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/54 "2014-05-19T18:37:34Z")

</div>

[=Ryvar;50833]  
re: Vertex Color - make sure you include the underlined line in your VertexFactory, or the color data will never get copied:  
[/]

Added the fix to the [wiki article on procedural mesh generation](https://wiki.unrealengine.com/Procedural_Mesh_Generation).

EDIT: Anyone, feel free to update the code on that page. I haven’t included 's code on UVs and bounds.

---

<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:** [May 19, 2014, 8:36pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/55 "2014-05-19T20:36:38Z")

</div>

[=dmacesic;52644]  
Added the fix to the [wiki article on procedural mesh generation](https://wiki.unrealengine.com/Procedural_Mesh_Generation).

EDIT: Anyone, feel free to update the code on that page. I haven’t included’s code on UVs and bounds.  
[/]

The reason I haven’t updated the code for UVs is because the vertex struct that contains UVs is not UPROPERTY() compatible, so I can’t make it a blueprint type struct any more.

```auto

//UPROPERTY() //<----- does not compile
FDynamicMeshVertex MyUVFriendlyVertex;

```

So if I made my UV update, it would break the code for anyone who wants to use it in Blueprints 🙂

Of course I could make my own USTRUCT that did not have that limitation but I figured at that point it was getting pretty project-specific 🙂

---

<div class="post-metadata">

**Author:** ![DayOfWar](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DayOfWar](https://forums.unrealengine.com/u/DayOfWar)\
**Post date:** [May 22, 2014, 3:00pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/56 "2014-05-22T15:00:16Z")

</div>

I would like to add some code that some may find useful.

With a slight change to the code you can improve the rendering quality of the Generatedmesh.

If you change the FGeneratedMeshSceneProxy constructor from  
Code:

[]  
class FGeneratedMeshSceneProxy : public FPrimitiveSceneProxy  
{  
public:

```
FGeneratedMeshSceneProxy(UGeneratedMeshComponent* Component)
	: FPrimitiveSceneProxy(Component)
	, MaterialRelevance(Component-&gt;GetMaterialRelevance())
{
	const FColor VertexColor(255,255,255);

	// Add each triangle to the vertex/index buffer
	for(int TriIdx=0; TriIdx&lt;Component-&gt;GeneratedMeshTris.Num(); TriIdx++)
	{
		FGeneratedMeshTriangle& Tri = Component-&gt;GeneratedMeshTris[TriIdx];

		const FVector Edge01 = (Tri.Vertex1 - Tri.Vertex0);
		const FVector Edge02 = (Tri.Vertex2 - Tri.Vertex0);

		const FVector TangentX = Edge01.SafeNormal();
		const FVector TangentZ = (Edge02 ^ Edge01).SafeNormal();
		const FVector TangentY = (TangentX ^ TangentZ).SafeNormal();

		FDynamicMeshVertex Vert0;
		Vert0.Position = Tri.Vertex0;
		Vert0.Color = VertexColor;
		Vert0.SetTangents(TangentX, TangentY, TangentZ);
		int32 VIndex = VertexBuffer.Vertices.Add(Vert0);
		IndexBuffer.Indices.Add(VIndex);

		FDynamicMeshVertex Vert1;
		Vert1.Position = Tri.Vertex1;
		Vert1.Color = VertexColor;
		Vert1.SetTangents(TangentX, TangentY, TangentZ);
		VIndex = VertexBuffer.Vertices.Add(Vert1);
		IndexBuffer.Indices.Add(VIndex);

		FDynamicMeshVertex Vert2;
		Vert2.Position = Tri.Vertex2;
		Vert2.Color = VertexColor;
		Vert2.SetTangents(TangentX, TangentY, TangentZ);
		VIndex = VertexBuffer.Vertices.Add(Vert2);
		IndexBuffer.Indices.Add(VIndex);
	}

	// Init vertex factory
	VertexFactory.Init(&VertexBuffer);

	// Enqueue initialization of render resource
	BeginInitResource(&VertexBuffer);
	BeginInitResource(&IndexBuffer);
	BeginInitResource(&VertexFactory);

	// Grab material
	Material = Component-&gt;GetMaterial(0);
	if(Material == NULL)
	{
		Material = UMaterial::GetDefaultMaterial(MD_Surface);
	}
}

```

[/]

To  
Code:

[]  
FGeneratedMeshSceneProxy(UGeneratedMeshComponent\* Component)  
: FPrimitiveSceneProxy(Component)  
, Material(NULL)  
, MaterialRelevance(Component-\>GetMaterialRelevance())  
{  
const FColor VertexColor(255, 255, 255);  
**TArray\<FVector\> Positions;**

```
	// Add each triangle to the vertex/index buffer
	for (int TriIdx = 0; TriIdx&lt;Component-&gt;GeneratedMeshTris.Num(); TriIdx++)
	{
		FGeneratedMeshTriangle& Tri = Component-&gt;GeneratedMeshTris[TriIdx];
		int32 VIndex;

		const FVector Edge01 = (Tri.Vertex1 - Tri.Vertex0);
		const FVector Edge02 = (Tri.Vertex2 - Tri.Vertex0);

		const FVector TangentX = Edge01.SafeNormal();
		const FVector TangentZ = (Edge02 ^ Edge01).SafeNormal();
		const FVector TangentY = (TangentX ^ TangentZ).SafeNormal();

		FDynamicMeshVertex Vert0;
		Vert0.Position = Tri.Vertex0;
		Vert0.Color = VertexColor;
		Vert0.SetTangents(TangentX, TangentY, TangentZ);

		**if (!Positions.Contains(Vert0.Position))
		{
			Positions.Add(Vert0.Position);
			VIndex = VertexBuffer.Vertices.Add(Vert0);
			IndexBuffer.Indices.Add(VIndex);
		}
		else
			IndexBuffer.Indices.Add(Positions.Find(Vert0.Position));

```

\*\*  
FDynamicMeshVertex Vert1;  
Vert1.Position = Tri.Vertex1;  
Vert1.Color = VertexColor;  
Vert1.SetTangents(TangentX, TangentY, TangentZ);

```
		**if (!Positions.Contains(Vert1.Position))
		{
			Positions.Add(Vert1.Position);
			VIndex = VertexBuffer.Vertices.Add(Vert1);
			IndexBuffer.Indices.Add(VIndex);
		}
		else
			IndexBuffer.Indices.Add(Positions.Find(Vert1.Position));

```

\*\*  
FDynamicMeshVertex Vert2;  
Vert2.Position = Tri.Vertex2;  
Vert2.Color = VertexColor;  
Vert2.SetTangents(TangentX, TangentY, TangentZ);

```
		**if (!Positions.Contains(Vert2.Position))
		{
			Positions.Add(Vert2.Position);
			VIndex = VertexBuffer.Vertices.Add(Vert2);
			IndexBuffer.Indices.Add(VIndex);
		}
		else
			IndexBuffer.Indices.Add(Positions.Find(Vert2.Position));**
	}

	// Init vertex factory
	VertexFactory.Init(&VertexBuffer);

	// Enqueue initialization of render resource
	BeginInitResource(&VertexBuffer);
	BeginInitResource(&IndexBuffer);
	BeginInitResource(&VertexFactory);

	// Grab material
	Material = Component-&gt;GetMaterial(0);
	if (Material == NULL)
	{
		Material = UMaterial::GetDefaultMaterial(MD_Surface);
	}
}

```

[/]

The change will keep you from adding redundant vertices to the VertexBuffer and will change this

 ![HighresScreenshot00001.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/f/9f7781c2772719ac10e006baf0d9c7c8d345945f.jpeg)

To

 ![HighresScreenshot00000.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/a/4ae35463fb7e5951d7101f57188f0eee1390a9e9.jpeg)

If You want to allow the GeneratedMeshComponent to cast a shadow you will need to change the CalcBounds function from

Code:

[]

FBoxSphereBounds UGeneratedMeshComponent::CalcBounds(const FTransform & LocalToWorld) const  
{  
FBoxSphereBounds NewBounds;  
NewBounds.Origin = FVector::ZeroVector;  
NewBounds.BoxExtent = FVector(HALF\_WORLD\_MAX,HALF\_WORLD\_MAX,HALF\_WORLD\_MAX);  
NewBounds.SphereRadius = FMath::Sqrt(3.0f \* FMath::Square(HALF\_WORLD\_MAX));  
return NewBounds;  
}

[/]

To  
Code:

[]  
FBoxSphereBounds UGeneratedMeshComponent::CalcBounds(const FTransform & LocalToWorld) const  
{  
FVector BoxPoint = FVector(10,10,10);  
return FBoxSphereBounds(FVector(10,0,0), BoxPoint, BoxPoint.Size()).TransformBy(LocalToWorld);

}  
[/]

Keep in mind that the changes to CalcBounds reflect the actually size of the geometry and will need to be changed if the geometry changes.

One last thing.  
If you want to be able to assign a material in the editor you will have to make a change in GameGeneratedActor.cpp from  
Code:

[]  
AGameGeneratedActor::AGameGeneratedActor(const class FPostConstructInitializeProperties& PCIP)  
: Super(PCIP)  
{

```
**TSubobjectPtr&lt;UGeneratedMeshComponent&gt; mesh = PCIP.CreateDefaultSubobject&lt;UGeneratedMeshComponent&gt;(this, TEXT("GeneratedMesh"));**

//Contains the points describing the polyline we are going to rotate
TArray&lt;FVector&gt; points;

points.Add(FVector(20, 5, 0));
points.Add(FVector(15, 6, 0));
points.Add(FVector(12, 7, 0));
points.Add(FVector(11, 8, 0));
points.Add(FVector(8, 7, 0));
points.Add(FVector(7, 6, 0));
points.Add(FVector(4, 5, 0));
points.Add(FVector(3, 4, 0));
points.Add(FVector(2, 3, 0));
points.Add(FVector(1, 4, 0));

TArray&lt;FGeneratedMeshTriangle&gt; triangles;
Lathe(points, triangles,128);
mesh-&gt;SetGeneratedMeshTriangles(triangles);

RootComponent = mesh;

```

}  
[/]

To  
Code:

[]  
AGameGeneratedActor::AGameGeneratedActor(const class FPostConstructInitializeProperties& PCIP)  
: Super(PCIP)  
{

```
 **mesh = PCIP.CreateDefaultSubobject&lt;UGeneratedMeshComponent&gt;(this, TEXT("GeneratedMesh"));**

//Contains the points describing the polyline we are going to rotate
TArray&lt;FVector&gt; points;

points.Add(FVector(20, 5, 0));
points.Add(FVector(15, 6, 0));
points.Add(FVector(12, 7, 0));
points.Add(FVector(11, 8, 0));
points.Add(FVector(8, 7, 0));
points.Add(FVector(7, 6, 0));
points.Add(FVector(4, 5, 0));
points.Add(FVector(3, 4, 0));
points.Add(FVector(2, 3, 0));
points.Add(FVector(1, 4, 0));

TArray&lt;FGeneratedMeshTriangle&gt; triangles;
Lathe(points, triangles,128);
mesh-&gt;SetGeneratedMeshTriangles(triangles);

RootComponent = mesh;

```

}  
[/]

Then add to GameGeneratedActor.h  
Code:

[]  
class AGameGeneratedActor : public AActor  
{  
GENERATED\_UCLASS\_BODY()

```
**TSubobjectPtr&lt;class UGeneratedMeshComponent&gt; mesh;**

void Lathe(const TArray&lt;FVector&gt;& points, TArray&lt;FGeneratedMeshTriangle&gt;& triangles, int segments = 64);

```

};  
[/]

Hope this helps out

---

<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:** [May 22, 2014, 5:42pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/57 "2014-05-22T17:42:06Z")

</div>

[=DayOfWar;55809]  
I would like to add some code that some may find useful.  
(…)  
Hope this helps out  
[/]

Looks good! The actual code I am using has diverged from the wiki code quite a bit, since that was meant as an example. But what you provide is valuable, and when I have a bit of time I’ll test it out and update the wiki.

---

<div class="post-metadata">

**Author:** ![milliams](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@milliams](https://forums.unrealengine.com/u/milliams)\
**Post date:** [May 28, 2014, 7:09pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/58 "2014-05-28T19:09:29Z")

</div>

I’ve just copied the code from the wiki example into my project and can create the lathed object in my map. However, it shows up with the default grey material rather than the black which it should have. My code includes the _ColorComponent_ by Ryvar above but it makes no difference. Has anyone else seen this or can anyone offer any advice?

Cheers.

---

<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:** [May 28, 2014, 8:11pm UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/59 "2014-05-28T20:11:44Z")

</div>

[=;61045]  
I’ve just copied the code from the wiki example into my project and can create the lathed object in my map. However, it shows up with the default grey material rather than the black which it should have. My code includes the _ColorComponent_ by Ryvar above but it makes no difference. Has anyone else seen this or can anyone offer any advice?

Cheers.  
[/]

In the Actor, define this Property:

```auto

	UPROPERTY(BlueprintReadWrite, Category = GeneratedActor)
	UMaterialInterface* Material;

```

Assign a material to the actor in a blue. In your actor, where you generate your mesh, use something like this:

```auto

       GeneratedMeshComponent->SetMaterial(0, Material);

```

In the code from the wiki, you would need to have a separate function in the actor for generating the mesh. You could then do spawn actor, set material, generate mesh, mesh-\>SetMaterial(0, Material);

HTH

---

<div class="post-metadata">

**Author:** ![TechAnim\_Tools](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/techanim_tools/32/1213818_2.png) [@TechAnim\_Tools](https://forums.unrealengine.com/u/TechAnim_Tools)\
**Post date:** [June 10, 2014, 6:53am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/60 "2014-06-10T06:53:08Z")

</div>

Oh god, this is amazing!

I love how the Blueprints are very close to ICE inside Softimage, where you can manage data/arrays/geometry with visual data…sweet!!!

Keep going guys, this is awesome!

---

<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:** [June 12, 2014, 12:59am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/61 "2014-06-12T00:59:39Z")

</div>

Dear Dmacesic,

I modified the wiki code to change this

```auto

//#if WITH_EDITOR
		ModelBodySetup->InvalidatePhysicsData();
//#endif

```

to this

```auto

		ModelBodySetup->ClearPhysicsMeshes();
		ModelBodySetup->BodySetupGuid = FGuid::NewGuid();

```

**InvalidatePhysicsData** would not package for me, causing package fail.

The above solution does package correctly 🙂

And most importantly! We still have custom collision thanks to you research!

I hope you like my change!

Enjoy!

---

<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:** [June 12, 2014, 2:40am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/62 "2014-06-12T02:40:59Z")

</div>

[=;73658]  
Dear Dmacesic,

I modified the wiki code to change this

```auto

//#if WITH_EDITOR
		ModelBodySetup->InvalidatePhysicsData();
//#endif

```

to this

```auto

		ModelBodySetup->ClearPhysicsMeshes();
		ModelBodySetup->BodySetupGuid = FGuid::NewGuid();

```

**InvalidatePhysicsData** would not package for me, causing package fail.

The above solution does package correctly 🙂

And most importantly! We still have custom collision thanks to you research!

I hope you like my change!

Enjoy!

[/]

Oh cool, they put in the cooking change. It’s not a problem, the wiki belongs to . And you are embarrassing me: the code is still Epic’s that I have just rehashed a bit… 😉

EDIT: Hmm, it’s still in the Roadmap, funny… You still have collisions on a packaged game?

---

<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:** [June 12, 2014, 4:12am UTC](https://forums.unrealengine.com/t/generate-procedural-mesh/1393/63 "2014-06-12T04:12:21Z")

</div>

[=dmacesic;73704]  
EDIT: Hmm, it’s still in the Roadmap, funny… You still have collisions on a packaged game?  
[/]

Well I got past package compiling , but I’ve been sorting through various asset errors for the past 2-3 hours, so i can’t say for sure yet, but at least I can verify it compiles now!

Will let you know!

I’m taking a break from waiting 1 hour to find out 1 asset didn’t make it and then fix that 1 asset and wait 1 hour again 🙂

🙂

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

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