Enum to string in Unreal 5
In Unreal 5 you can convert enums to their string representation using UEnum::GetValueAsString
.
This helps with printing readable log messages.
UENUM(BlueprintType)
enum class ECharacterCameraMode : uint8 {
FirstPerson UMETA(DisplayName = "First Person"),
ThirdPerson UMETA(DisplayName = "Third Person"),
MAX UMETA(Hidden)
};
void SomeActor::ChangeCameraMode(ECharacterCameraMode camera_mode) {
UE_LOGFMT(LogTemp,
Verbose,
"Changing camera mode to {enum_value}.",
("enum_value", *UEnum::GetValueAsString(camera_mode)));
// Rest of code...
}
and our output is then:
LogTemp: Verbose: Changing camera mode to ECharacterCameraMode::FirstPerson.