Could I move this PhysX code to my game module ?

I added this piece of code inside PrimitiveComponent.cpp because the default UPrimitiveComponent::ComputePenetration was giving me some troubles :

    bool UPrimitiveComponent::ComputePenetrationCustom(FMTDResult & OutMTD, UPrimitiveComponent& CollisionPrimitive)
    #if WITH_PHYSX
    const PxRigidActor* PRigidBody0 = CollisionPrimitive.BodyInstance.GetPxRigidActor();
    if (PRigidBody0 == NULL || PRigidBody0->getNbShapes() == 0)
    return false;
    const PxTransform PGlobalPose0 = PRigidBody0->getGlobalPose();
    const PxRigidActor* PRigidBody1 = BodyInstance.GetPxRigidActor();
    if (PRigidBody1 == NULL || PRigidBody1->getNbShapes() == 0)
    return false;
    const PxTransform PGlobalPose1 = PRigidBody1->getGlobalPose();
    // Get all the shapes from the actors
    // TODO: we should really pass the shape from the overlap info since doing it this way we do an overlap test twice
    TArray<PxShape*> PShapes0;
    int32 NumTargetShapes0 = PRigidBody0->getShapes(PShapes0.GetData(), PShapes0.Num());
    TArray<PxShape*> PShapes1;
    int32 NumTargetShapes1 = PRigidBody1->getShapes(PShapes1.GetData(), PShapes1.Num());
    for (int32 PShapeIdx0 = 0; PShapeIdx0 < PShapes0.Num(); ++PShapeIdx0)
    const PxShape * PShape0 = PShapes0[PShapeIdx0];
    // Calc shape global pose
    PxTransform PGeomPose0 = PGlobalPose0.transform(PShape0->getLocalPose());
    GeometryFromShapeStorage GeomStorage0;
    PxGeometry * PGeom0 = GetGeometryFromShape(GeomStorage0, PShape0, true);
    if (PGeom0)
    for (int32 PShapeIdx1 = 0; PShapeIdx1 < PShapes1.Num(); ++PShapeIdx1)
    const PxShape * PShape1 = PShapes1[PShapeIdx1];
    // Calc shape global pose
    PxTransform PGeomPose1 = PGlobalPose1.transform(PShape1->getLocalPose());
    GeometryFromShapeStorage GeomStorage1;
    PxGeometry * PGeom1 = GetGeometryFromShape(GeomStorage1, PShape1, true);
    if (PGeom1)
    PxVec3 POutDirection;
    bool bSuccess = PxGeometryQuery::computePenetration(POutDirection, OutMTD.Distance, *PGeom0, PGeomPose0, *PGeom1, PGeomPose1);
    if (bSuccess)
    if (POutDirection.isFinite())
    OutMTD.Direction = P2UVector(POutDirection);
    return true;
    UE_LOG(LogPhysics, Warning, TEXT("UPrimitiveComponent::ComputePenetration: MTD returned NaN"));
    return false;
    return false;

The code works just fine, however compiling the engine myself is a lot of extra work and time, and also I have some problems with the compiled version of the engine that I don’t have with the binary version, so I would like to move this function to my game code (not as a UPrimitiveComponent member, of course).

I have followed this tutorial on the wiki, but the compiler still complains about some classes and functions like GeometryFromShapeStorage, GetGeometryFromShape or P2UVector.

Is there any way to include those classes into my project ?

Please post the error message you’re getting. Also, try posting the questions over at

Hey mate only way i can think of is adding the librarys to the project propertys.
But following the tutorial from Rama should work.

Also take a look at a AnswerHubpost i did.
When trying to get it to work I did this but i whent back and set it up as Rama did.

 /** Convert PhysX PxVec3 to Unreal FVector */
 ENGINE_API FVector P2UVector(const PxVec3& PVec); 

Is located in “PhysicsPublic.h”

Hi jCoder, it just complains about GeometryFromShapeStorage and GetGeometryFromShape being undeclared.

Here are the errors, but they’re in spanish :

Hi WCode. Including PhysicsPublic.h solved some of the errors, that one should be included on the Rama’s tutorial.
And yep, the Rama’s method works fine, the problem is that GeometryFromShapeStorage and GetGeometryFromShape are not really PhysX code, they are located inside “Runtime\Engine\Private\Collision\PhysXCollision.h” and that file doesn’t seem to come with the binary version of the engine.

I’ve been able to make it work by copying GeometryFromShapeStorage and GetGeometryFromShape from the source into my own code, but I don’t know if that goes against the EULA. (???)

I don’t understand why some classes are hidden to the binary version, since we have source code access anyway.

The error code (C3861) helps because you can reference Microsoft docs, even if the message isn’t clear from the context.

If they’re under the Runtime directory, it’s OK. Editor and Developer are off limits. From section 1a of the EULA:

Great, thanks for your help jCoder.