Printing & Logging in Unreal Engine 5 C++
if(GEngine)
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("Some message"));
UE_LOG(LogTemp, Warning, TEXT("Some message"));
int MyInt = 3;
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("int: %d"), MyInt));
UE_LOG(LogTemp, Warning, TEXT("int: %d"), MyInt);
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);
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"));
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));
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);
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());
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());
UObject* MyObject = NewObject<UObject>(this, TEXT("MyObject"));
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("UObject: %s"), MyObject ? *MyObject->GetName() : TEXT("NULL")));
UE_LOG(LogTemp, Warning, TEXT("UObject: %s"), MyObject ? *MyObject->GetName() : TEXT("NULL"));