# Procedural Mesh Falls Through the Floor Despite Physics and Collision Settings

**URL:** <https://forums.unrealengine.com/t/procedural-mesh-falls-through-the-floor-despite-physics-and-collision-settings/2203004>\
**Category:** C++\
**Tags:** procedural-mesh-comp, unreal-engine, Physics, procedural-mesh, Collision, procedural, question, CPP\
**Created:** [December 11, 2024, 11:34am UTC](https://forums.unrealengine.com/t/procedural-mesh-falls-through-the-floor-despite-physics-and-collision-settings/2203004 "2024-12-11T11:34:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IdrisKhan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IdrisKhan](https://forums.unrealengine.com/u/IdrisKhan)\
**Post date:** [December 11, 2024, 11:34am UTC](https://forums.unrealengine.com/t/procedural-mesh-falls-through-the-floor-despite-physics-and-collision-settings/2203004/1 "2024-12-11T11:34:12Z")

</div>

I’m working on generating a procedural mesh from a skeletal mesh at runtime and have hit a bit of a roadblock. I’m using `UProceduralMeshComponent` to create the mesh, and while everything appears to be set up correctly (gravity is enabled, physics is simulated, and collision settings seem fine), the mesh keeps falling through the floor.  
Here’s the code:

> UProceduralMeshComponent\* USlicableCharacterComponent::GenerateProceduralMeshFromSkeleton(USkeletalMeshComponent\* SkeletalMesh)  
> {  
> if (!SkeletalMesh)  
> {  
> UE\_LOG(LogTemp, Error, TEXT(“SkeletalMesh is null!”));  
> return nullptr;  
> }
> 
> ```
> UProceduralMeshComponent* ProcMeshComponent = NewObject<UProceduralMeshComponent>(this, UProceduralMeshComponent::StaticClass(), TEXT("ProceduralMeshComponent"));
> 
> if (AActor* Owner = GetOwner())
> {
> UCapsuleComponent* CapsuleComponent = Owner->FindComponentByClass<UCapsuleComponent>();
> if (CapsuleComponent)
> {
> ProcMeshComponent->AttachToComponent(CapsuleComponent, FAttachmentTransformRules::KeepRelativeTransform);
> }
> else
> {
> UE_LOG(LogTemp, Error, TEXT("Capsule not found!"));
> }
> }
> 
> ProcMeshComponent->RegisterComponent();
> 
> ProcMeshComponent->bUseComplexAsSimpleCollision = false;
> 
> ProcMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
> ProcMeshComponent->SetSimulatePhysics(true);
> ProcMeshComponent->SetEnableGravity(true);
> 
> ProcMeshComponent->SetCollisionObjectType(ECC_PhysicsBody);
> ProcMeshComponent->SetCollisionResponseToAllChannels(ECR_Block);
> ProcMeshComponent->SetCollisionResponseToChannel(ECC_Pawn, ECR_Ignore);
> 
> ProcMeshComponent->SetWorldTransform(SkeletalMesh->GetComponentTransform());
> 
> ConvertSkeletalMeshToProceduralMesh(SkeletalMesh, 0, ProcMeshComponent);
> 
> return ProcMeshComponent;
> 
> ```
> 
> }
> 
> USlicableCharacterComponent::USlicableCharacterComponent()  
> {  
> }
> 
> void USlicableCharacterComponent::ConvertSkeletalMeshToProceduralMesh(  
> USkeletalMeshComponent\* InSkeletalMeshComponent, int32 LODIndex, UProceduralMeshComponent\* InProcMeshComponent)  
> {  
> FSkeletalMeshRenderData\* SkMeshRenderData = InSkeletalMeshComponent-\>GetSkeletalMeshRenderData();  
> const FSkeletalMeshLODRenderData& DataArray = SkMeshRenderData-\>LODRenderData[LODIndex];  
> FSkinWeightVertexBuffer& SkinWeights = \*InSkeletalMeshComponent-\>GetSkinWeightBuffer(LODIndex);
> 
> ```
> TArray<FVector> VerticesArray;
> TArray<FVector> Normals;
> TArray<FVector2D> UV;
> TArray<FColor> Colors;
> TArray<FProcMeshTangent> Tangents;
> 
> for (int32 j = 0; j < DataArray.RenderSections.Num(); j++)
> {
> // Get number of vertices and offset
> const int32 NumSourceVertices = DataArray.RenderSections[j].NumVertices;
> const int32 BaseVertexIndex = DataArray.RenderSections[j].BaseVertexIndex;
> 
> for (int32 i = 0; i < NumSourceVertices; i++)
> {
> const int32 VertexIndex = i + BaseVertexIndex;
> 
> // Get skinned vertex position
> const FVector3f SkinnedVectorPos = USkeletalMeshComponent::GetSkinnedVertexPosition(
> InSkeletalMeshComponent, VertexIndex, DataArray, SkinWeights);
> FVector VertexPosition(SkinnedVectorPos.X, SkinnedVectorPos.Y, SkinnedVectorPos.Z);
> VerticesArray.Add(VertexPosition);
> 
> // Calc normals and tangents
> const FVector3f ZTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentZ(
> VertexIndex);
> const FVector3f XTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentX(
> VertexIndex);
> 
> Normals.Add(FVector(ZTangentStatic.X, ZTangentStatic.Y, ZTangentStatic.Z));
> Tangents.Add(FProcMeshTangent(FVector(XTangentStatic.X, XTangentStatic.Y, XTangentStatic.Z), false));
> 
> // Get UVs
> const FVector2f SourceUVs = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.GetVertexUV(VertexIndex, 0);
> FVector2D ResUVs(SourceUVs.X, SourceUVs.Y);
> UV.Add(ResUVs);
> 
> // Dummy vertex colors
> Colors.Add(FColor(0, 0, 0, 255));
> }
> }
> 
> // Get index buffer
> FMultiSizeIndexContainerData IndicesData;
> DataArray.MultiSizeIndexContainer.GetIndexBuffer(IndicesData.Indices);
> 
> for (int32 j = 0; j < DataArray.RenderSections.Num(); j++)
> {
> TArray<int32> Tris;
> 
> // Get number of triangles and offset
> const int32 SectionNumTriangles = DataArray.RenderSections[j].NumTriangles;
> const int32 SectionBaseIndex = DataArray.RenderSections[j].BaseIndex;
> 
> // Iterate over indices and add triangles
> for (int32 i = 0; i < SectionNumTriangles; i++)
> {
> int32 TriVertexIndex = i * 3 + SectionBaseIndex;
> Tris.Add(IndicesData.Indices[TriVertexIndex]);
> Tris.Add(IndicesData.Indices[TriVertexIndex + 1]);
> Tris.Add(IndicesData.Indices[TriVertexIndex + 2]);
> }
> 
> // Create the procedural mesh section
> InProcMeshComponent->CreateMeshSection(j, VerticesArray, Tris, Normals, UV, Colors, Tangents, true);
> 
> InProcMeshComponent->ContainsPhysicsTriMeshData(true);
> InProcMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
> 
> }
> 
> ```
> 
> }

I’ve been stuck on this for **days** now, and honestly, it’s getting really frustrating. I’ve tried everything I can think of. IDK what to do at this point!..  
Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![MightyMoe2212](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MightyMoe2212](https://forums.unrealengine.com/u/MightyMoe2212)\
**Post date:** [March 31, 2025, 8:59pm UTC](https://forums.unrealengine.com/t/procedural-mesh-falls-through-the-floor-despite-physics-and-collision-settings/2203004/2 "2025-03-31T20:59:10Z")

</div>

Just found this post because I had the same Issue and from your component naming a very similar idea ^^

I tried the same with a StaticMesh as source for generating a ProceduralMesh and it also has fallen through the ground.

After debugging I found out, that the _CollisionConvexElems_ array of the mesh was empty. So I checkt what is responsible for setting this up and well I’m responsible for it 😅. Maybe like you I thought just set ‘ **true** ’ in _CreateMeshSection_ is enough and the physical object is created automatically but no you have to do it by hand. But their is, at least for static meshes, a very simple solution for it:

```cpp
       // Iterate over all convex hulls on static mesh..
       const int32 NumConvex = StaticMesh->GetBodySetup()->AggGeom.ConvexElems.Num();
       for (int ConvexIndex = 0; ConvexIndex < NumConvex; ConvexIndex++)
       {
           // Copy convex verts to ProcMesh
           FKConvexElem& MeshConvex = StaticMesh->GetBodySetup()->AggGeom.ConvexElems[ConvexIndex];
           ProceduralMesh->AddCollisionConvexMesh(MeshConvex.VertexData);
       }

```

You need to get the BodySetup from your origin mesh and put them into the procedural mesh. (This is by the way from the _KismetProceduralMeshLibrary.cpp_ which I now use because it does exactly what I need, sadly no out of the box functions for SkeletalMesh 🫤)

So conclusion for everyone else who might find this in future, it isn’t enough to create/copy all the structure for rendering, you also have to create/copy the structure for physics manually!

Happy Coding!
