How to Copy Convex Collision Meshes from one StaticMesh to another StaticMesh

Hello friends,

I am trying to copy the Collision Meshes (in my case the convex decomposition collision meshes) from one StaticMesh to another StaticMesh.

After some looking around I read that the Collision Meshes are stored in the BodySetup and so I tired something like this:

UBodySetup* OldBodySetup = MyOldStaticMeshActor->GetStaticMeshComponent()->GetBodySetup();
FKAggregateGeom OldAggregateGeom = OldBodySetup->AggGeom;

MyNewStaticMeshActor->GetStaticMeshComponent()->GetBodySetup()->AddCollisionFrom(OldAggregateGeom);

This works for simple collsion but strangely not for the convex decomposition meshes “MyNewStaticMeshActor”.

EDIT: If I open the “receiver” static mesh in the editor, I can see in the collision section that there are indeed 10 Convex Elements, so the copy process worked but the collisions are not shown (see picture 1) and also not working.
But here comes the strange thing: As soon as I change ANY collision setting with the mouse pointer (like “Double Sided Geometry”, the collision meshes show up! (see picture 2).
So it seems that changing any setting in the collisions section in the editor “refreshes” something and that makes the collision meshes appear and also work.

Does anyone have a clue what to add to the code (the refreshing part)



?

Thank you in advance,

Alex

May I ask why you want to do this? What problem are you trying to solve?

Hi Dan,

I have some CAD-models (StaticMeshActors) in my world that are moving around and I want to get a notice shortly BEFORE they collide. So I need a collision mesh that is slightly bigger than the static mesh. That way I get a collision notice before the actual static meshes “collide”.
I do this by taking the StaticMesh and convert it to a FDynamicMesh3, move each vertex “outward” by 5cm, convert the FDynamicMesh3 into a new StaticMesh and use this new bigger one for calculating the Convex Decomposition Collision Mesh. In the last step, I use this Convec Decomposition Mesh and copy it back into the original StaticMesh. And so I have a StaticMesh with a Collision Mesh that has 5cm distance to the surface.

If you have any better idea how to “inflate” a collision mesh so that it has some distance to the surface of the StaticMesh, I would be mooooore than happy to hear that.

Greetings

Edit (solution):
found out that it works if I add two lines to the code: InvalidatePhysicsData and CreatePhysicsMeshes
So the whole thing looks like this:

UBodySetup* OldBodySetup = MyOldStaticMeshActor->GetStaticMeshComponent()->GetBodySetup();  
FKAggregateGeom OldAggregateGeom = OldBodySetup->AggGeom;   
UBodySetup* NewBodySetup = MyNewStaticMeshActor->GetStaticMeshComponent()->GetBodySetup();   
NewBodySetup->AddCollisionFrom(OldAggregateGeom); 
NewBodySetup->InvalidatePhysicsData(); 
NewBodySetup->CreatePhysicsMeshes();
1 Like

Awesome, thanks for the clarifying. Please give such information in the future to avoid any potential XY Problem.

(I don’t have any better solution than the one you have given.)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms