Printing & Logging in Unreal Engine 5 C++



// Writing On Screen
if(GEngine)
    GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("Some message!"));   


// Writting in Output Log 
UE_LOG(LogTemp, Warning, TEXT("Some message!")); 



// print int
int MyInt = 3;
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("int: %d"), MyInt));
UE_LOG(LogTemp, Warning, TEXT("int: %d"), MyInt);



// print float
float MyFloat = 10.5f;
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("float: %f"), MyFloat));
UE_LOG(LogTemp, Warning, TEXT("float: %f"), MyFloat);



// print boolean
bool bMyBool = true;
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("bool: %s"), bMyBool ? TEXT("true") : TEXT("false")));
UE_LOG(LogTemp, Warning, TEXT("bool: %s"), bMyBool ? TEXT("true") : TEXT("false"));



// print enum
ECustomEnum EMyEnum = ECustomEnum::ValueA;
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("Enum: %s"), *UEnum::GetValueAsString(EMyEnum)));
UE_LOG(LogTemp, Warning, TEXT("Enum: %s"), *UEnum::GetValueAsString(EMyEnum));



// print FString
FString MyString = TEXT("Hello World");
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FString: %s"), *MyString));
UE_LOG(LogTemp, Warning, TEXT("FString: %s"), *MyString);



// print FName
FName MyName = TEXT("Hello World");
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FName: %s"), *MyName.ToString()));
UE_LOG(LogTemp, Warning, TEXT("FName: %s"), *MyName.ToString());



// print FVector
FVector MyVector = FVector(1, 2, 3);
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FVector: %s"), *MyVector.ToString()));
UE_LOG(LogTemp, Warning, TEXT("FVector: %s"), *MyVector.ToString());