PhysX Source Guide

UE4 uses Nvidia PhysX and APEX as its underlying physics engine. PhysX takes care of core functionality like rigid body simulation, while APEX takes care of destruction and clothing. The source cod...

Updated over 4 years ago Edit Page Revisions

UE4 uses Nvidia PhysX and APEX as its underlying physics engine. PhysX takes care of core functionality like rigid body simulation, while APEX takes care of destruction and clothing. The source code is fully available for both which makes debugging and modifying behavior easy.

Compiling

This command generates the project files and compiles:

 call RunUAT.bat BuildPhysX -TargetPlatforms=Win64 -TargetConfigs=profile -TargetWindowsCompilers=VisualStudio2015 -SkipSubmit

You may need to edit BuildPhysX.Automation.cs and remove the "[RequireP4]" attribute line.

If you only want the project files add -SkipBuild to the above command. The visual studio solution will be available here:

Engine\Source\ThirdParty\PhysX3\PhysX_3.4\Source\compiler\Win64\VS2015\PhysX.sln

Connecting to UE4

UE4 will automatically find the appropriate binaries when it compiles the engine module. You can either do a full recompile, or simply make a trivial modification (enter a few new lines) to this file:

Engine\Source\Runtime\Engine\Private\PhysicsEngine\PhysXLibs.cpp

Disabling Optimizations

Turning off optimizations on an arbitrary build can be helpful. To do this on windows edit the CMake file found here: Engine\Source\ThirdParty\PhysX3\PhysX_3.4\Source\compiler\cmake\windows\CMakeLists.txt

In this file you'll see the following:

SET(CMAKE\_CXX\_FLAGS\_DEBUG "/Od ${WINCRT\_DEBUG} /RTCu /Zi")
SET(CMAKE\_CXX\_FLAGS\_CHECKED "/Ox ${WINCRT\_NDEBUG} /Zi")

SET(CMAKE\_CXX\_FLAGS\_PROFILE "/Ox ${WINCRT\_NDEBUG} /Zi")

SET(CMAKE\_CXX\_FLAGS\_RELEASE "/Ox ${WINCRT\_NDEBUG} /Zi")

You can turn off optimization on any config by changing /Ox to /Od. Then recompile PhysX using the above guide

Using a Debug Build

The PhysX debug build relies on the debug CRT. To make this work you will need to edit BuildConfiguration.xml to have:

true

In general it's easier to use a checked build which will still fire asserts without requiring the full debug CRT.