UE4之PVD调试

发布时间 2023-03-26 00:28:59作者: 可可西

PhysX在编译时必须开启PX_SUPPORT_PVD宏(PhysX的Debug、Profiler版本的库会开启该宏),才能支持 PVD 的调试。

游戏缺省会使用localhost,端口为5425,连接超时时间为100ms来与Physx Visual Debugger工具建立连接。

如果要修改PVD的端口号,只能修改pvd.exe的31150000(为5425的16进制小端序)数值,如下:

 

引擎连接PVD的逻辑在:UnrealEngine\Engine\Source\Runtime\PhysicsCore\Private\PhysXSupportCore.cppvoid PvdConnect(FString Host, bool bVisualization)函数中。

 

注意1

在使用PVD之前,必须先启动Physx Visual Debugger工具。

 

通过命令行参数连接Physx Visual Debugger工具

UE4Editor.exe "%GameDir%\MyGame.uproject" TestMap_Main -game -pvd  // 单机启动TestMap_Main地图,并自动连接本机正在运行的PhysX Visual Debugger

 

通过控制台命令连接Physx Visual Debugger工具

pvd CONNECT  // 连接本机正在运行的PVD  注:调用void PvdConnect(FString Host, bool bVisualization)函数

pvd CONNECT 10.46.80.77  // 连接ip为10.46.80.77上正在运行的PVD  注:缺省端口为5425,连接超时时间为100ms

DISCONNECT  // 断开与PVD的连接

 

Physx Visual Debugger主界面

注:使用左手系(Left-Handed),与虚幻引擎保证画面一致

 

线框模式:

 

在Physx Visual Debugger中不同rigid(刚体)的颜色

 

在Physx Visual Debugger中实时查看游戏的物理

 

在编辑器Preview模式下所有物体都会创建物理对象

>    UE4Editor-Engine-Win64-Debug.dll!UPrimitiveComponent::ShouldCreatePhysicsState() Line 1409    C++
     UE4Editor-Engine-Win64-Debug.dll!UActorComponent::CreatePhysicsState(bool bAllowDeferral=true) Line 1462    C++
     UE4Editor-Engine-Win64-Debug.dll!UActorComponent::ExecuteRegisterEvents(FRegisterComponentContext * Context=0x0000000000000000) Line 1537    C++
     UE4Editor-Engine-Win64-Debug.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld=0x0000024082b9b580, FRegisterComponentContext * Context=0x0000000000000000) Line 1223    C++
     UE4Editor-Engine-Win64-Debug.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister=2147483647, FRegisterComponentContext * Context=0x0000000000000000) Line 4582    C++
     UE4Editor-Engine-Win64-Debug.dll!ULevel::IncrementalUpdateComponents(int NumComponentsToUpdate=0, bool bRerunConstructionScripts=true, FRegisterComponentContext * Context=0x0000000000000000) Line 1094    C++
     UE4Editor-Engine-Win64-Debug.dll!ULevel::UpdateLevelComponents(bool bRerunConstructionScripts=true, FRegisterComponentContext * Context=0x0000000000000000) Line 971    C++
     UE4Editor-Engine-Win64-Debug.dll!UWorld::UpdateWorldComponents(bool bRerunConstructionScripts=true, bool bCurrentLevelOnly=true, FRegisterComponentContext * Context=0x0000000000000000) Line 1963    C++
     UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::Map_Load(const wchar_t * Str=0x00000241c3ab9fb2, FOutputDevice & Ar={...}) Line 2771    C++
     UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::HandleMapCommand(const wchar_t * Str=0x00000241c3ab9fb2, FOutputDevice & Ar={...}, UWorld * InWorld=0x0000000000000000) Line 6148    C++
     UE4Editor-UnrealEd-Win64-Debug.dll!UEditorEngine::Exec(UWorld * InWorld=0x0000000000000000, const wchar_t * Stream=0x00000241c3aba080, FOutputDevice & Ar={...}) Line 5705    C++
     UE4Editor-UnrealEd-Win64-Debug.dll!UUnrealEdEngine::Exec(UWorld * InWorld=0x0000000000000000, const wchar_t * Stream=0x00000241c3aba080, FOutputDevice & Ar={...}) Line 697    C++
     UE4Editor-UnrealEd-Win64-Debug.dll!FEditorFileUtils::LoadMap(const FString & InFilename={...}, bool LoadAsTemplate=false, const bool bShowProgress=true) Line 2554    C++

 

注1:在编辑器Preview模式下,打开地图时,World的bEnableTraceCollsion为trueECollisionEnabled::NoCollision的物体也会创建物理对象

 

注2:PIE下,InitWorld时传入缺省的InitializationValues()参数,使得World的bEnableTraceCollsion为false,但由于此时存在2个World(Preview World和PIE World),在PVD中依然会显示ECollisionEnabled::NoCollision的物体

 

注3:Standalone下,打开地图时,InitWorld时传入缺省的InitializationValues()参数,使得World的bEnableTraceCollsion为falseECollisionEnabled::NoCollision的物体不会创建物理对象

 

注意2

因此,要在Standalone模式下,使用PhysX Visual Debugger工具来查看对象的物理。

 

PhysX中函数的耗时情况

 

PhysX内存统计

 

PhysX中线程执行情况

 

对上图的后面时间段进行放大:

 

注意3

Physx Visual Debugger工具非常不稳定,容易发生崩溃。

在使用时,建议工具栏上点击Disconnect按钮停止采集,保存到pxd2文件后,再查看场景中的对象和性能相关的数据。

 

参考

UE4物理模块(一)---概述与可视化调试