Printing & Logging in Unreal Engine 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 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());