Code For you, Using UWorld* To Get PhysX Scene
Dear Community,
PhysX Wiki
I’ve added to my PhysX Wiki showing you some code and additional #includes to use to get access to the PhysX Scene in a way where you can do low level multi-threaded PhysX coding!
's Wiki on PhysX Coding in UE4
**PhysX + UE4 Code For You!** Here's the code that you can use to get started in multi-thread friendly way, please see my higher post for more places to look for PhysX code in the UE4 code base. ``` //PhysX #include "PhysXIncludes.h" //For the ptou conversions #include "PhysicsPublic.h" //For Scene Locking using Epic's awesome helper macros like SCOPED_SCENE_READ_LOCK #include "Runtime/Engine/Private/PhysicsEngine/PhysXSupport.h" void SomeClass::SomeFunction(UWorld* World) { check(World); //if crash here world was not valid, needs to be investigated, did it come from a UObject? FPhysScene* PhysScene = World->GetPhysicsScene(); // Scene Lock for Multi-Threading PxScene* SyncScene = PhysScene->GetPhysXScene(PST_Sync); SCOPED_SCENE_READ_LOCK(SyncScene); //now you can use the PhysX scene in multi-threaded fashion within this function context! // - } ``` Note on UWorld*
Any Actor can easily just call GetWorld() to get you the UWorld* ptr
UWorld* World = YourActor->GetWorld(); UObjects can do the same but its not quite as reliable depending on the UObject
**Conclusion** Have fun doing low level multi-threaded PhysX coding using the awesome Epic helper functions of PhysXSupport.h! Enjoy!