B站教学链接:https://space.bilibili.com/449549424?spm_id_from=333.1007.0.0
一、屏幕打印
参数说明:
第一个参数-1,默认值
第二个参数5.0f,打印到屏幕上显示的时间
第三个参数FColor::Red,打印到屏幕上的颜色
第四个参数TEXT("123"),打印到屏幕上的内容
1.1 打印文本内容
//UE4打印输出日志
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("123"));
1.2 打印字符串
//打印字符串
FString mystring = "1234";
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("string : %s"), *mystring));
1.3 打印浮点型变量
//打印浮点型变量
float Health = 5.0f;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Health is : %f"), Health));
1.4 打印整型变量
//打印整型型变量
int32 Number = 5;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Number is : %d"), Number));
二、日志打印
2.1 自定义输出日志
参数说明:
YouLog:自定义的Log名称
Log:日志的颜色
DECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All);
UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));
2.2 官方自带的打印输出日志
官方的输出日志有三种,三种分别代表输出的日志类型是日志类型,警告类型,错误类型,颜色也不相同
//灰色
UE_LOG(LogTemp,Log,TEXT("This is grey text!"));
//黄色
UE_LOG(LogTemp,Warning,TEXT("This is yellow text!"));
//红色
UE_LOG(LogTemp,Error,TEXT("This is red text!"));
2.3 打印
打印字符串
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );
打印整型
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );
打印浮点型
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );
打印向量文章来源:https://www.toymoban.com/news/detail-558107.html
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),
*MyCharacter->GetActorLocation().ToString());
打印FName文章来源地址https://www.toymoban.com/news/detail-558107.html
UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"),
*MyCharacter->GetFName().ToString());
到了这里,关于UE4 C++ 之 打印的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!