Simulate physics for a UProceduralMeshComponent

I have created a simple UProceduralMeshComponent (just a triangle) and passed ‘true’ to the last parameter in UProceduralMeshComponent::CreateMeshSection to generate collision. My goal is to create several different UProceduralMeshComponent with collision, and simulate physics on them so that they fall down and move around in the world according to the physics simulation (imagine creating a type of ball using UProceduralMeshComponent and then enabling SimulatePhysics so that it bounces around). When I call SetSimulatePhysics(true) however, the procedural mesh still floats up in the air where it was placed. I’ve also tried setting the collision profile, enabling gravity on the procedural mesh component, and waking the rigid body, but no luck. What do I have to do to get the UProceduralMeshComponent to simulate physics?

Here’s my initialization in the constructor:

    this->Top = ObjectInitializer.CreateDefaultSubobject<UProceduralMeshComponent>(this, TEXT("TopMesh"));
    this->RootComponent = this->Top;

    TArray<FVector> vertices;

    vertices.Add(FVector(0, 0, 0));
    vertices.Add(FVector(0, 100, 0));
    vertices.Add(FVector(0, 0, 100));

    TArray<int32> Triangles;
    Triangles.Add(0);
    Triangles.Add(1);
    Triangles.Add(2);

    TArray<FVector> normals;
    normals.Add(FVector(1, 0, 0));
    normals.Add(FVector(1, 0, 0));
    normals.Add(FVector(1, 0, 0));

    TArray<FVector2D> UV0;
    UV0.Add(FVector2D(0, 0));
    UV0.Add(FVector2D(0, 10));
    UV0.Add(FVector2D(10, 10));

    TArray<FColor> vertexColors;
    vertexColors.Add(FColor(100, 100, 100, 100));
    vertexColors.Add(FColor(100, 100, 100, 100));
    vertexColors.Add(FColor(100, 100, 100, 100));

    TArray<FProcMeshTangent> tangents;
    tangents.Add(FProcMeshTangent(1, 1, 1));
    tangents.Add(FProcMeshTangent(1, 1, 1));
    tangents.Add(FProcMeshTangent(1, 1, 1));

    this->Top->CreateMeshSection(1, vertices, Triangles, normals, UV0, vertexColors, tangents, true);

Here’s my Actor’s BeginPlay where I set the physics properties:

this->Top->SetSimulatePhysics(true);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, TEXT("3"));

this->Top->SetCollisionObjectType(ECollisionChannel::ECC_PhysicsBody);
this->Top->SetCollisionProfileName(TEXT("PhysicsActor"));
this->Top->SetCollisionResponseToAllChannels(ECR_Block);
this->Top->SetEnableGravity(true);
this->Top->WakeRigidBody();
this->Top->SetMobility(EComponentMobility::Movable);

this->SetActorEnableCollision(true);

Hello,

Try moving your SetSimulatePhysics to the constructor. If this doesn’t work, you could also attempt to create a blueprint based on this class and set simulate physics to true in the construction script of that blueprint.

Hello,
If you want PMC simulate physics,you need 2 step;
1.set bUseComplexAsSimpleCollision false befoer set SetSimulatePhysics(true) tick, i am set construct;
2.use AddCollisionConvexMesh add collistion mesh,becase set UseComplexAsSimpleCollision false,cant auto build collsionmesh;

1 Like