【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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM