【UE4 C++】打印字符串与输出日志

2021/5/4 20:27:25

本文主要是介绍【UE4 C++】打印字符串与输出日志,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

打印屏幕

  • 默认打印屏幕

    // 打印至屏幕
    FString screenMessage = "(AddOnScreenDebugMessage)    Hello world!";
    GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Green, screenMessage);
    
    // 打印至屏幕
    UKismetSystemLibrary::PrintString(this, "(UKismetSystemLibrary::PrintString)   Hello world!");
    
    

    image

输出log

  • 默认类别打印log

    UE_LOG(LogTemp, Log, TEXT("(UE_LOG-logTemp)    Hello world!"));
    
  • 自定义类别打印log

    // .h 自定义日志分类
    DECLARE_LOG_CATEGORY_CLASS(GMDebugLog, Log, All);
    
    // .cpp 输出日志 自定义分类
    UE_LOG(GMDebugLog, Warning, TEXT("(UE_LOG-logTemp)    Hello world!"));
    UE_LOG(GMDebugLog, Error, TEXT("(UE_LOG-GMDebugLog)    Hello world!"));
    
  • 带变量打印log

    	
    //创建FString 变量 FString::Printf
    FString playerName = "User";
    int32 healthValue = 100;
    FString outputMessage1 = FString::Printf(TEXT("Name is %s, health value is %d"), *playerName, healthValue);
    UE_LOG(LogTemp, Warning, TEXT("FStringFormatArg: %s"), *outputMessage1);
    
    //创建FString变量 FString::Format
    TArray<FStringFormatArg> args;
    args.Add(FStringFormatArg(playerName));
    args.Add(FStringFormatArg(healthValue));
    
    FString outputMessage2 = FString::Format(TEXT("Name is {0}, health value is  {1}"), args);
    UE_LOG(LogTemp, Warning, TEXT("FString::Format: %s"), *outputMessage2);
    

    image



这篇关于【UE4 C++】打印字符串与输出日志的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程