Linker error in Editor builds using ExecuteOnPxRigidDynamicReadWrite

When I try to compile code that uses the ExecuteOnPxRigidDynamicReadWrite lambda, I get the following linker error in the Development Editor configuration:

error LNK2019: unresolved external symbol "class physx::PxScene * __cdecl GetPhysXSceneFromIndex(int)"

Specifically I am trying to implement a class that extends UWheeledVehicleMovementComponent, and I’m using that lambda to call the PxVehicleNoDrive setup function:

	ExecuteOnPxRigidDynamicReadWrite(UpdatedPrimitive->GetBodyInstance(), [&](PxRigidDynamic* PRigidDynamic)
	{
		PVehicleNoDrive->setup(GPhysXSDK, PRigidDynamic, *PWheelsSimData);
		PVehicleNoDrive->setToRestState();

		// cleanup
		PWheelsSimData->free();
	});

This code successfully compiles and links on the Development Game configuration. I have PhysX and APEX enabled in PublicDependencyModuleNames for my project as well.

I suspect that the GetPhysXSceneFromIndex function (from Source\Runtime\Engine\Private\PhysicsEngine\PhysXSupport.cpp, line 204) might be undefined in the Editor configurations despite WITH_PHYSX seemingly being defined everywhere else in the code.

Is there anything I might be overlooking?

Hi,

I think You got linker error because GetPhysXSceneFromIndex isn’t exported from the engine dll.

Try change:
PxScene* GetPhysXSceneFromIndex(int32 InSceneIndex);

to:

ENGINE_API PxScene* GetPhysXSceneFromIndex(int32 InSceneIndex);

I fixed this by using FBodyInstance::ExecuteOnPhysicsReadWrite and calling GetPxRigidDynamic_AssumesLocked within the lambda.

FBodyInstance* BodyInstance = UpdatedPrimitive->GetBodyInstance();
BodyInstance->ExecuteOnPhysicsReadWrite([&] {
	PxRigidDynamic* PRigidDynamic = BodyInstance->GetPxRigidDynamic_AssumesLocked();
});

It effectively does the same thing as ExecuteOnPxRigidDynamicReadWrite but is accessible without modifying the engine.