x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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


Product Version: UE 4.10
Tags:
more ▼

asked Nov 20 '15 at 06:38 AM in Bug Reports

avatar image

djw
23 2 7 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Nov 24 '15 at 06:51 PM

avatar image

Sean L ♦♦ STAFF
43.5k 485 152 442

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question