博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ue4的UE_LOG
阅读量:6379 次
发布时间:2019-06-23

本文共 3958 字,大约阅读时间需要 13 分钟。

说明:本文为Wiki上的RAMA大神文章的大致翻译

游戏模式:

在游戏模式下,你需要在游戏的快捷方式后面加 -Log,才会在游戏中显示。

 

编辑器模式(Play In Editor):

你可以在Output窗口中看到log信息。

如果想在游戏中看到,需要到Engin.ini中修改参数添加"GameCommandLine=-log,如果没有,则需要按~,输入-Log命令开启。

 

快速使用:

UE_LOG(LogTemp, Warning, TEXT("Your message"));

不用设置标签,简单快速。

 

设置拥有自己标签的Log:

在你的游戏头文件中加入:

//General LogDECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All); //Logging during game startupDECLARE_LOG_CATEGORY_EXTERN(YourInit, Log, All); //Logging for your AI systemDECLARE_LOG_CATEGORY_EXTERN(YourAI, Log, All); //Logging for Critical Errors that must always be addressedDECLARE_LOG_CATEGORY_EXTERN(YourCriticalErrors, Log, All);

这样输出的Log你就可以知道是哪个部分的,这也是UE_Log很有用的原因。

在你的游戏Cpp文件中:

//General LogDEFINE_LOG_CATEGORY(YourLog); //Logging during game startupDEFINE_LOG_CATEGORY(YourInit); //Logging for your AI systemDEFINE_LOG_CATEGORY(YourAI); //Logging for Critical Errors that must always be addressedDEFINE_LOG_CATEGORY(YourCriticalErrors);

 

Log格式:

Log Message

//"This is a message to yourself during runtime!"UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));

Log an FString

%s strings are wanted as TCHAR* by Log, so use *FString()//"MyCharacter's Name is %s"UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );

Log an Int

//"MyCharacter's Health is %d"UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );

Log a Float

//"MyCharacter's Health is %f"UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );

Log an FVector

//"MyCharacter's Location is %s"UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),     *MyCharacter->GetActorLocation().ToString());

Log an FName

//"MyCharacter's FName is %s"UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"),     *MyCharacter->GetFName().ToString());

Log an FString,Int,Float

//"%s has health %d, which is %f percent of total health"UE_LOG(YourLog,Warning,TEXT("%s has health %d, which is %f percent of total health"),    *MyCharacter->GetName(), MyCharacter->Health, MyCharacter->HealthPercent);

Log的颜色设置:

//"this is Grey Text"UE_LOG(YourLog,Log,TEXT("This is grey text!"));//"this is Yellow Text"UE_LOG(YourLog,Warning,TEXT("This is yellow text!"));//"This is Red Text"UE_LOG(YourLog,Error,TEXT("This is red text!"));

可以看得出第二个参数是是用来控制颜色的。

 

传递客户端信息(网络模式):

PlayerController->ClientMessage("Your Message");

命令行命令以及Engine.ini配置:

Log conventions (in the console, ini files, or environment variables)

[cat] = a category for the command to operate on, or 'global' for all categories.标签,没有设置就显示所有的Log[level] = verbosity level, one of: none, error, warning, display, log, verbose, all, default关卡,显示某某关卡的Log

At boot time, compiled in default is overridden by ini files setting, which is overridden by command line

Log console command usage

Log list - list all log categoriesLog list [string] - list all log categories containing a substringLog reset - reset all log categories to their boot-time defaultLog [cat] - toggle the display of the category [cat]Log [cat] off - disable display of the category [cat]Log [cat] on - resume display of the category [cat]Log [cat] [level] - set the verbosity level of the category [cat]Log [cat] break - toggle the debug break on display of the category [cat]

Log command line

-LogCmds=\"[arguments],[arguments]...\"           - applies a list of console commands at boot time-LogCmds=\"foo verbose, bar off\"         - turns on the foo category and turns off the bar category

Environment variables

Any command line option can be set via the environment variable UE-CmdLineArgs

set UE-CmdLineArgs=\"-LogCmds=foo verbose breakon, bar off\"

Config file

In DefaultEngine.ini or Engine.ini:

[Core.Log]global=[default verbosity for things not listed later][cat]=[level]foo=verbose break
Rama后面的一篇文章提供了显示代码行号、函数名称、类名等功能: https://wiki.unrealengine.com/Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!

转载于:https://www.cnblogs.com/blueroses/p/6037981.html

你可能感兴趣的文章
Linux学习之01_基础命令介绍
查看>>
.net获取IP和MAC地址
查看>>
eclipse
查看>>
更换pip源到国内镜像
查看>>
最短路径算法
查看>>
服务端崩溃原因记录
查看>>
js中的 for, for in, for of foreach,filter使用
查看>>
Effective_C++ (条款02) 尽量以 const,enum,inline替换 #define
查看>>
常用单词9
查看>>
php课程 5-18 数组排序和合并拆分函数有哪些
查看>>
js如何生成[n,m]的随机数
查看>>
导入模块
查看>>
metasploit快速入门
查看>>
redis centos7
查看>>
【HDU 2196】 Computer(树的直径)
查看>>
人工智能实战2019第三次作业_李大
查看>>
linux下查看端口占用情况以及服务启动的目录
查看>>
freemarker split字符串分割 遍历map
查看>>
【原创】SSM框架(2):多数据源支持,动态配置依赖的数据源
查看>>
Aop_思想篇
查看>>