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"

ProceduralMeshComponent doesn't collide with anything

I'm trying to create procedural objects that collide with the world, but I can't make it work.

I'm creating a simple box, with physics disabled; I'm using the First Person C++ template as testing room.

This is the code, executed on an Actor when the game starts:

 TArray mVertices;
 TArray mIndices;
 TArray mNormals;
 TArray mUvs;
 TArray mTangents;
 TArray mVertexColors;
 mMesh->bUseComplexAsSimpleCollision = false;
 UKismetProceduralMeshLibrary::GenerateBoxMesh(FVector(100, 100, 100), mVertices, mIndices, mNormals, mUvs, mTangents);
 mMesh->CreateMeshSection(0, mVertices, mIndices, mNormals, mUvs, mVertexColors, mTangents, true);

Then I'm grabbing pre-made cubes that are in the scene and I move them so that they should hit the procedural cube; except that they don't, they pass right through it.

If I grab the procedural cube and move it around, it doesn't hit anything. If I enable "simulate physics" on the procedural cube, it just fall through the ground.

Product Version: UE 4.15
more ▼

asked Mar 03 '17 at 06:05 PM in C++ Programming

avatar image

58 4 8 17

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Actually I discovered a method of UProceduralMeshComponent called "AddCollisionConvexMesh", which takes the list of vertices that compose the collision shell basically. That plus the bUseComplexAsSimpleCollision boolean set to false will make the procedural objects behave like they should.

To make the cube behave like any object now I just call that method after creating the section and I pass the vertices of the section to it.

Like this:

 mesh->bUseComplexAsSimpleCollision = false;
 mMesh->CreateMeshSection(0, mVertices, mIndices, mNormals, mUvs, mVertexColors, mTangents, true);

It seems to work fine (the errors are gone), even with more complex procedural meshes! :D

Thanks for the help pulp_user :)

more ▼

answered Mar 04 '17 at 06:08 PM

avatar image

58 4 8 17

avatar image pulp_user Mar 04 '17 at 06:11 PM

Glad I could help :)

avatar image pulp_user Mar 04 '17 at 06:13 PM

Although it still interests me if the above would work. The AddCollisionConvexMesh probably provides a primitive, of which the mass is known. Can you just try out if it works with the mass override (I may need that in the future myself :D)

(comments are locked)
10|2000 characters needed characters left

I have not verified this assumption, but here is what I think: You set bUseComplexAdSimpleCollision = false, which means you are telling the engine to not use the visible mesh as collision, but instead some special collision geometry, that is made up of primitives. But you don't provide that. You only provide the geometry, but you tell the engine not to use it for collision. So the engine is left with nothing to calculate collision. If you set this to true, it might work.

more ▼

answered Mar 03 '17 at 06:33 PM

avatar image

1.2k 46 29 58

avatar image Beriol Mar 03 '17 at 07:48 PM

Actually you're right, if I set it to true then if I grab pre-made cubes and throw them to the procedural cube they get blocked!

But there is a reason if I set it to false: if I try to simulate physics on the procedural cube, then it throws me this error and it doesn't simulate anything:

PIE:Warning: Warning Trying to simulate physics on ''/Game/FirstPersonCPP/Maps/UEDPIE_0_FirstPersonExampleMap.FirstPersonExampleMap:PersistentLevel.BP_MyActor.UCustomProceduralComponent'' but it has ComplexAsSimple collision. LogPhysics:Error: PHYSX: (d:\build++ue4+release-4.14+physx_compile\sync\engine\source\thirdparty\physx\physx_3.4\source\physx\src\NpRigidBodyTemplate.h 479) eINVALID_PARAMETER : RigidBody::setRigidBodyFlag: dynamic meshes/planes/heightfields are not supported!

How can I solve this so that I can simulate physics AND have the procedural cube collide with other things?

avatar image pulp_user Mar 04 '17 at 02:49 PM

A second wild guess :D Simulating physics only works when the physics engine knows about a mass of an object. Since you just provided vertecies and triangles the engine may not know what mass your object has. Have you tried to use the mass override in the details panel of your mesh istance, and just set it to 100 or whatever?

avatar image Beriol Mar 06 '17 at 01:10 PM

Sure! I tried but it doesn't work, it keeps throwing me the errors I mentioned above.

The thing goes probably like you said: with bUseComplexAsSimpleCollision set to false the engine needs to know the shape of the object, and that's what AddCollisionConvexMesh() is for. With the boolean set to true it works for simple collisions only (meaning that other objects can collide with the cube), while it's not enough to simulate physics.

One more thing: right now I'm having another issue regarding physics (physics handles in particular). I described the problem here: https://forums.unrealengine.com/showthread.php?138646-PhysicsHandleComponent-doesn-t-move-when-SetTargetLocation()-is-called-in-C&p=675951#post675951

Maybe you can look at it, when you have time? Since you know your way with physics objects :)

(comments are locked)
10|2000 characters needed characters left
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