# How can I output the value of an Enum to a log?

**URL:** <https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097>\
**Category:** C++\
**Tags:** Replication, ENUM, unreal-engine, log, CPP, question\
**Created:** [June 5, 2014, 4:38pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097 "2014-06-05T16:38:54Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![IrishKilter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrishKilter](https://forums.unrealengine.com/u/IrishKilter)\
**Post date:** [June 5, 2014, 4:38pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/1 "2014-06-05T16:38:54Z")

</div>

I’ve always been a big ENUM user inside UDK with uScript. I enjoy how they can keep things very clean if implemented right. However, I can’t seem to figure out how to actually use UE\_LOG() to log their current value.

There appears to be no way (that I have found anyways) to convert the value of an ENUM into that of String, or even an Int which would give me a numerical value of its setting at the very least. I am trying to currently log my custom classes Role and RemoteRole (I understand that RemoteRole should be the opposite of Role (or at least in UDK)). But it won’t compile.

```
UE_LOG(InvLog, All, TEXT("Replication Properties: ROLE = '%s' ,REMOTEROLE = '%s') ") *Role, GetRemoteRole() );
```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [June 5, 2014, 9:34pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/2 "2014-06-05T21:34:56Z")

</div>

#There Is a Way

I wrote a Wiki tutorial on it here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Original code was created with help of Marc Audy

FText is Localized

can use .ToString() to get it to FString if you want

```
FText GetVictoryEnumAsString(EVictoryEnum::Type EnumValue)
{
  const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EVictoryEnum"), true);
  if(!EnumPtr) return NSLOCTEXT("Invalid","Invalid","Invalid");
 
  return EnumPtr->GetDisplayNameText(EnumValue);
}
```

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [June 5, 2014, 9:41pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/3 "2014-06-05T21:41:48Z")

</div>

Well i did simple search and i find UEnum class

> **[UEnum](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/UEnum/)**
>
> Reflection data for an enumeration.

Which i assume stores all enum information for blueprint, there some static functions you might be interested in

> **[UEnum::GetValueAsString](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/UEnum/GetValueAsString/1/)**

My guess is you simply put template with enum type and in 2nd argument you value, but i don’t know how to get enum path 😛 but you might figure out somehow

Definitly your enum declaration needs to be precursored with UENUM() so engine and UEnum class to see it.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [June 5, 2014, 9:42pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/4 "2014-06-05T21:42:51Z")

</div>

oh you faster ;p well i will leave my incomplete anwser as it got links to UEnum refrence

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [June 6, 2014, 12:38am UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/5 "2014-06-06T00:38:21Z")

</div>

always nice to hear from you !

---

<div class="post-metadata">

**Author:** ![IrishKilter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrishKilter](https://forums.unrealengine.com/u/IrishKilter)\
**Post date:** [June 7, 2014, 12:08pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/6 "2014-06-07T12:08:26Z")

</div>

Yeah sorry, I don’t really understand this.

I’m assuming because Role located inside Actor.h is of type TEnumAsByte I can’t convert it back to a regular UEnum in order to use the GetDisplayName?

I’m not entirely sure what the point of TEnumAsByte is versus a regular UEnum in general, but it seems to have no other function than “GetValue()”.

Which is fine if it’s not possible at the moment, but a little annoying that any defined Epic ENUM that’s set to TEnumAsByte I can’t log for testing.

---

<div class="post-metadata">

**Author:** ![sailentz\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sailentz\_1](https://forums.unrealengine.com/u/sailentz_1)\
**Post date:** [July 17, 2014, 8:48pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/7 "2014-07-17T20:48:54Z")

</div>

GetDisplayNameText function is only accessible when WITH\_EDITOR is defined, so pay attention. I’ve corrected wiki page mentioned above.

---

<div class="post-metadata">

**Author:** ![Kmack](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kmack/32/706181_2.png) [@Kmack](https://forums.unrealengine.com/u/Kmack)\
**Post date:** [October 7, 2016, 10:27pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/8 "2016-10-07T22:27:05Z")

</div>

If you’d like to do this without creating a function to convert the enum, here’s a simple way to use the method outlined above:

```
void AMyGameWeapon::SetWeaponState(EWeaponState::Type NewState)
{
     const UEnum* WeaponStateEnum = FindObject<UEnum>(ANY_PACKAGE, TEXT("EWeaponState"));
     UE_LOG(LogMyGameWeapon, Log, TEXT("SetWeaponState called on weapon %s with state %s (Role %s)")
    		, *GetNameSafe(this)
    		, *(WeaponStateEnum ? WeaponStateEnum->GetEnumName(NewState) : TEXT("<Invalid Enum>"))
    		, *UEnum::GetValueAsString(TEXT("Engine.ENetRole"), Role));

```

The first line finds a pointer to the enum object from its namespace, and then in the UE\_LOG call, we use that enum pointer to get a string value to output. Important to note is that the pointer isn’t guaranteed to be valid, so use a ternary operator to ensure that you safely handle a case where the pointer doesn’t exist.

This UE\_LOG statement also supplies an example of grabbing a string from an enum that isn’t enclosed in a namespace and whose path is known.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b41939ed1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b41939ed1](https://forums.unrealengine.com/u/anonymous_user_b41939ed1)\
**Post date:** [May 16, 2017, 1:06pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/9 "2017-05-16T13:06:50Z")

</div>

thanks a lot @sailentz, the unreal documentarion is really bad, finally found the ■■■■ preprocessor directive for editor

---

<div class="post-metadata">

**Author:** ![FunAndFriendly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FunAndFriendly](https://forums.unrealengine.com/u/FunAndFriendly)\
**Post date:** [August 10, 2020, 5:34pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/10 "2020-08-10T17:34:25Z")

</div>

For me, this worked:

Enum Declared:

```
UENUM()
enum EGripState
{
	Open UMETA(DisplayName = "Stopped"),
	CanGrip UMETA(DisplayName = "CanGrip"),
	Gripping UMETA(DisplayName = "Gripping"),
};

```

Property declared .h

```
UPROPERTY(BlueprintReadOnly)
	TEnumAsByte<EGripState> GripState;

```

Logged in .cpp

```
    UE_LOG(LogTemp, Warning, TEXT("GripState: %i"), GripState);

```

TEnumAsByte claims to “to store enumeration values as bytes in a type-safe way”:

> **[TEnumAsByte](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Core/Containers/TEnumAsByte/)**
>
> Template to store enumeration values as bytes in a type-safe way.

---

<div class="post-metadata">

**Author:** ![Jon-Claude](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jon-Claude](https://forums.unrealengine.com/u/Jon-Claude)\
**Post date:** [November 29, 2021, 1:50am UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/11 "2021-11-29T01:50:24Z")

</div>

For me @Shadowrivers answer steered me in the right direction. Just adding a little more detail for others who may need it. Using `MyEnum` as our enum.

```
UE_LOG(LogTemp, Log, TEXT("MyEnum is %s"), *UEnum::GetValueAsString(MyEnum));

```

Note: Since %s doesn’t accept a FString we have to prepend the \*.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 4, 2022, 8:54pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/12 "2022-08-04T20:54:42Z")

</div>

this is not working for me

---

<div class="post-metadata">

**Author:** ![FunGames55](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fungames55/32/710746_2.png) [@FunGames55](https://forums.unrealengine.com/u/FunGames55)\
**Post date:** [April 9, 2023, 5:13pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/13 "2023-04-09T17:13:46Z")

</div>

Assuming your enum has the `UENUM` macro on the declaration, you can use

```auto
UEnum::GetDisplayValueAsText(value).ToString();

```

to get the declared UMETA(DisplayName = “MyEnumValue”) value as an `FString`.

---

<div class="post-metadata">

**Author:** ![Syther](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Syther](https://forums.unrealengine.com/u/Syther)\
**Post date:** [May 24, 2023, 7:33pm UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/14 "2023-05-24T19:33:35Z")

</div>

```auto
UE_LOG(LogTemp, Warning, TEXT("EnumState: %s"), *UEnum::GetValueAsString<EEnumState>(EnumVariable));

This is exactly what's posted for enums.
```

---

<div class="post-metadata">

**Author:** ![NLaurito](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nlaurito/32/1052420_2.png) [@NLaurito](https://forums.unrealengine.com/u/NLaurito)\
**Post date:** [July 13, 2023, 7:08am UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/15 "2023-07-13T07:08:07Z")

</div>

`UE_LOG(LogTemp, Warning, TEXT("EnumState: %s"), *UEnum::GetValueAsString(EnumVariable).ToString());`

I had to add .ToString() for it to compile. Also, specifying the `<EnumType>` is not necessary.

It’s so interesting to see this forum topic evolve over the years 🙂

---

<div class="post-metadata">

**Author:** ![Snipe3000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Snipe3000](https://forums.unrealengine.com/u/Snipe3000)\
**Post date:** [September 21, 2023, 6:08am UTC](https://forums.unrealengine.com/t/how-can-i-output-the-value-of-an-enum-to-a-log/285097/16 "2023-09-21T06:08:37Z")

</div>

LNK2019: unresolved external symbol class UEnum
