当前位置:网站首页>UE4 调试常用的打印信息方法
UE4 调试常用的打印信息方法
2022-07-28 23:17:00 【华为云】
前言
作为一名程序猿,在日常开发中肯定少不了在代码中加入日志,日志能及时的反馈给我们代码运行时的数据和信息。在本篇文章中,就让我们来学习一下如何在 UE 中去输出日志。
常用调式方法
在虚幻引擎中常用的打印日志方法有三种,分别是:UE_LOG, AddOnScreenDebugMessage,以及在蓝图中使用 Print String。
在代码中使用 UE_LOG
使用UE_LOG 打印日志可以控制打印的内容,如果每个日志按照自己的级别来分类显示,那开发者就可以迅速的查找到对应的日志内容。这些分类包括:
- Fatal
- Error
- Warning
- Display
- Log
- Verbose
- VeryVerbose
接下来,咱们来看如何来定义 UE_LOG。
在 .h 头文件中声明日志,声明日志类别宏有三个参数:
DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity);- 参数 CategoryName 是你定义的类别名
- 参数 DefaultVerbosity 日志级别
- 参数 CompileTimeVerbosity 是要在代码中编辑的最大详情类别
例如:
DECLARE_LOG_CATEGORY_EXTERN(LoginLog, Log, All);在 .cpp 中定义日志宏:
DEFINE_LOG_CATEGORY(LoginLog)参考案例如下:
void AFPSGameModeLogic::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage){ Super::PreLogin(Options, Address, UniqueId, ErrorMessage); if (!ErrorMessage.IsEmpty()) { return; } if (!UniqueId.IsValid()) { ErrorMessage = "You are logging in with empty account"; UE_LOG(LoginLog, Error, TEXT("PreLogin: logging in with empty account")); } ....}使用 AddOnScreenDebugMessage 来输出到屏幕
除了使用 UE_LOG,咱还可以使用 AddOnScreenDebugMessage 方法在当前屏幕视口中去打印日志。
具体使用方法如下:
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("Server not connected yet.")));在蓝图中使用 Print String
在蓝图中任意拖动到节点 PrintString 即可选择在屏幕或者日志输出栏中输出日志,只要勾选上就会执行对应的操作,非常的方便,具体节点内容如下:

最后
本文简单的介绍了三种在 UE 开发中经常用到的日志调试方法,分别是 UE_LOG, AddOnScreenDebugMessage 和 Print String,你学会了吗?
边栏推荐
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- 【MySQL 8】Generated Invisible Primary Keys(GIPK)
- 异步模式之工作线程
- 将Word中的表格以图片形式复制到微信发送
- rk3399 9.0驱动添加Powser按键
- Basic knowledge of PHP language (super detailed)
- I was asked several questions about string in the interview. Can you answer them?
- MySQL sub database and sub table and its smooth expansion scheme
- PTA (daily question) 7-69 narcissus number
- 会议OA项目之会议通知&会议反馈&反馈详情功能
猜你喜欢

15. Model evaluation and selection

I was asked several questions about string in the interview. Can you answer them?

16.偏差、方差、正则化、学习曲线对模型的影响
![[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)](/img/0b/d6defd524f83e69b40b5878ffe2e3c.png)
[basic course of flight control development 8] crazy shell · open source formation uav-i2c (laser ranging)

Educational Codeforces Round 132 (Rated for Div. 2)【A~C】
![[development tutorial 10] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - Bluetooth ble transceiver](/img/06/5e417bb97e309b6ee27dc693cabb85.png)
[development tutorial 10] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - Bluetooth ble transceiver

2022dasctfjuly empowerment competition (reappearance)

Api 接口优化的那些技巧

我不建议你使用SELECT *

requestVideoFrameCallback() 简单实例
随机推荐
Basic knowledge of PHP language (super detailed)
CUDA相关
SQL Server 只有数据库文件,没有日志文件,恢复数据时报1813错误的解决方案
Still writing a lot of if to judge? A rule executor kills all if judgments in the project
2022DASCTF7月赋能赛(复现)
PTA (daily question) 7-73 turning triangle
Html+css+php+mysql realize registration + login + change password (with complete code)
手把手教你安装Latex(保姆级教程)
How to solve the problem that the Oracle instance cannot be started
追踪伦敦银实时行情的方法
C语言括号匹配(栈括号匹配c语言)
Surfacecontrol and surfaceflinger communication
DRF - web development mode, API interface, API interface testing tool, restful specification, serialization and deserialization, DRF installation and use
Outlier detection and open set identification (1)
最长上升子序列
DRF - paging, JWT introduction and principle, JWT quick use, JWT source code analysis, JWT custom return format, custom user issued token, custom token authentication class
【esn】 学习回声状态网络
1331. Array sequence number conversion: simple simulation question
COPU陆首群教授应邀在开放原子全球开源峰会上做主旨演讲
Camera Hal OEM module ---- CMR_ preview.c