BlueRoseNote/02-Note/演讲与教程笔记/虚幻开放日2023/总有一个你不知道的虚幻引擎调试技巧.md

80 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 蓝图
## 蓝图调试器
位于菜单栏-工具-调试-蓝图调试器,主要有变量信息以及调用堆栈。
可以开启异常时中断蓝图来定位异常位置。位于
- 编辑器偏好设置-通用-试验性功能-蓝图-异常时中断蓝图。
- DefaultEditorPerProjectUserSettings.ini
- `[/Script/UnrealEd.EditorExperimentalSettings]`
- `bBreakOnExceptions=True`
## 在蓝图中触发对应的情况
一些情况与数据很难马上出发,可以使用一下情况直接还原指定状态:
- UFUNCTION中添加**CallInEditor**
- 在蓝图函数中勾选编辑器中调用
- 使用编辑器的蓝图函数库
- Python
- Puerts Editor
## PrintString & AddOnScreenDebugMessage()
李米娜有一个`FName Key`选项可以指定一个Key这样就不会打印出大量数据只会显示当前数据。
# Logs
- Shipping 开启: bUseLoggingInShipping=true (adb log中不显示)启动参数-log:在命令行中显示log
- 修改Log的显示级别
- 控制台命令log LogName NewVerbosity:运行时修改Log的显示级别控制台命令:log global error
- 配置文件参数:DefaultEngine.ini:[Core.Log] global=error
- 启动参数:-ini:Engine:[Core.Log]:global=error
# VisualLogger
# 作弊管理器CheatManager
代码位于CheatManager.h/cpp
# 调试相机DebugCamera
- 快捷键
- 默认快捷键为~
- 可以在 Baselnput.ini中修改默认快捷键/或在Userlnput.ini中重载`[/Script/Engine.Playerlnput]`
- `+DebugExecBindings=(Key=Semicolon,Command="ToggleDebugCamera"`
- `+DebugExecBindings=(Key=Apostrophe,Command="ToggleForceDefaultMaterial")`
- 控制台命令ToggleDebugCamera
- 控制台命令Teleport:将角色移动到debug 相机注视处
- 控制台命令slomo 0.1:所有运行逻辑放缓10倍
# Obj
console命令推荐在打包阶段使用检查UObject的回收情况。具体可以参考UEngine::HandleObjCommand
# VisualStudio
可以通过设置强制不优化部分代码
- 独立c++文件:
- Checkout(使用P4或修改文件(使用git)C++文件会因为adaptive unity build的机制单独编译
- BuildConfiguration.xml:`<BuildConfiguration><bAdaptiveUnityDisablesOptimizations>true<|..>`
- Target.cs:bAdaptiveUnityDisablesOptimizations = true;
- 单个模块:
- 单个模块:
- BuildConfiquration.xml:`<ModuleConfiguration><DisableOptimizeCode><ltem>ModuleName</..>`
- Build.cs:OptimizeCode = CodeOptimization.InShippingBuildsOnly or CodeOptimization.Never
- Target.cs:DisableOptimizeCodeForModules数组
- 代码块:
- UE_DISABLE_OPTIMIZATION / UE_ENABLE_OPTIMIZATION
- UE_ENABLE_OPTIMIZATION_SHIP / UE_DISABLE_OPTIMIZATION_SHIP(shipping)
- Target.cs: UE_CHECK_DISABLE_OPTIMIZATION=1在打包机上设置避免包含未优化代码
## 跳过执行语句
- 拖动当前指示运行代码位置的黄色箭头。
- Ctrl+Shift+F10Set Next StateMent。
- 按住Ctrl+点击黄色箭头
## 查看其他模块的全局变量
在监视窗口中使用ModuleName!VariableName查看全局变量
- UnrealEditor-Core!GConfig
- UnrealEditor-Engine!GPlayInEditorContextString
- UnrealEditor-Core!GFrameCounter
![[VisualStudio_Watcher_Module.png|800]]
## Natvis
- Visual Studio Natvis框架可以自定义数据类型在调试器变量窗口中显示的方式
- Unreal的 Natvis实现:`Engine\Extras\VisualStudioDebugging\Unreal.Natvis`
- 安装方式:将Unreal.Natvis复制到`C:\Users\<user>\Documents|Visual Studio 2022\Visualizers\`路径下
- 修改立即生效
![[VisualStudio_Natvis.png|800]]