Problem with separate PhysX scene running in the background

Hello everyone.
I would like to run a simple simulation of some physics element of the scene in a background thread, so that I can fast-forward it by simulating it as fast as the CPU is able to, and when I’m done with it I can report back the data and use it from within the Unreal Engine.
In order to achieve such a goal, my idea was to do the following:

  • Create a background thread by inheriting my own class from FRunnable
  • Create a PxScene in that separate thread
  • Add a few rigid StaticMeshComponents in a blueprint actor, pass a reference to them to my FRunnable inherited class so that I can use their FBodyInstance and FBodySetup to re-create actors in my background physX scene.
  • Adda a simple plane in the simulation or add some static meshes to use as a “floor” in the simulation.
  • Step physics multiple times (PxScene::simulate(); PxScene::fetchResults(true):wink:

When I added only dynamic actors to the PhysX background scene everything is fine: I can access the references to StaticMeshComponents, access the FBodySetup and I can call the FBodySetup::AddShapesToRigidActor() function just fine. I need to set some data by hand (filter data, materials, etc) but in the end I can run the simulation and it goes well.

On the other hand, I recently tried to add a static mesh instead of a basic plane and hell broke loose:

  • When I try to collide a dynamic convex hull versus a static box, as soon as the two shape touches the convex hull is “shot” much far away, just like if the PhysX was overestimating the amount of correction needed to separate the two objects.
  • Same happens when I try a dynamic convex vs a static convex.
  • When I tried colliding a sphere against the simple static box, everything seems to be working perfectly.
  • When I try colliding a sphere with a static convex hull, the sphere keeps on bouncing on it, never coming to a rest.

I will post a reduced code example, if anyone asks for it; right now I can attach the physx nvidia debugger files that I recorded attempting to debug the entire thing. The scene form the PIE is PxScene 4, the scene of my background thread is PxScene 6. As everyone can see, the two scenes are almost identical, the only difference I could find is that only one contact is generated in the PIE scene while I have 2 contacts (the static object generates a contact as well). And yet the behavior is different since the sphere never comes to a rest.
I am also attaching another test, which involves a dynamic convex vs static convex. The relevant scenes are PxScene 6 and 8 in this file. I know that a few values are little different from PIE and background scenes (e.g: mass of dynamic actor), but the results are so different that it boggles my mind.

If anyone has any idea about what is going on, I’d love to hear about it.
.