# TNameOf does not work for UEnums?

**URL:** <https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506>\
**Category:** Rendering\
**Tags:** reflection, UEnum, assertion-failed, unreal-engine, CPP, question\
**Created:** [February 27, 2018, 7:40pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506 "2018-02-27T19:40:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaDummy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaDummy](https://forums.unrealengine.com/u/DaDummy)\
**Post date:** [February 27, 2018, 7:40pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/1 "2018-02-27T19:40:20Z")

</div>

I’m trying to retrieve the name of an enum type in a template.

I found **TNameOf\<T\>** which seems to be meant to achieve exactly this for seemingly all types known to the unreal reflection system, but it simply throws an assertion instead. What am I doing wrong here?

**Sample code:**

```
UENUM(BlueprintType)
enum class EMyUEnumType : uint8
{
    One,
    Two,
    Three
};

FName name = TNameOf<EMyUEnumType>::GetName(); // Hits an assertion ("crashes")
```

---

<div class="post-metadata">

**Author:** ![DaDummy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaDummy](https://forums.unrealengine.com/u/DaDummy)\
**Post date:** [February 27, 2018, 8:06pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/2 "2018-02-27T20:06:42Z")

</div>

I resorted to using the following workaround until UHT is adjusted to generate correct specializations for TNameOf:

```
// Once in a common header
#define Workaround_Expose_TNameOf(type) \
template<> \
struct TNameOf<type> \
{ \
	FORCEINLINE static TCHAR const* GetName() \
	{ \
		return TEXT(#type); \
	} \
}

// After every UEnum (replace EMyUEnumType by the enum's typename)
Workaround_Expose_TNameOf(EMyUEnumType);
```

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [February 28, 2018, 7:16am UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/3 "2018-02-28T07:16:29Z")

</div>

Hey!

Ive linked this before on another answer…  
Rama did a good explanation about enums… if you wanna get enum name which is reflected…  
Maybe this is the proper way or atleast a good starting point 😉

> **[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...

---

<div class="post-metadata">

**Author:** ![DaDummy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaDummy](https://forums.unrealengine.com/u/DaDummy)\
**Post date:** [February 28, 2018, 1:56pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/4 "2018-02-28T13:56:45Z")

</div>

Can you please provide an example based on that explanation by Rama on how to achieve what I am asking for? As it stands this right now this is not even an attempt to answer my question 😕

I provided code samples of what I am looking for. Please use them 🙂

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [February 28, 2018, 2:02pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/5 "2018-02-28T14:02:30Z")

</div>

Hey Sure

```
UENUM(BlueprintType)
enum class EMyUEnumType : uint8
{
     One UMETA(DisplayName="One"),
     Two UMETA(DisplayName="TWO"),
     Three UMETA(DisplayName="Three")

 };

EMyUEnumType EnumValue;

FString EnumString = GetEnumValueAsString<EMyUEnumType >("EMyUEnumType ", EnumValue)));
```

---

<div class="post-metadata">

**Author:** ![DaDummy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaDummy](https://forums.unrealengine.com/u/DaDummy)\
**Post date:** [February 28, 2018, 3:57pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/6 "2018-02-28T15:57:48Z")

</div>

Looks like you didn’t understand my question. I’m looking for a way to retrieve “EMyUEnumType” from the type (and without macros) instead of having to pass it as a parameter myself.

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [February 28, 2018, 6:07pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/7 "2018-02-28T18:07:43Z")

</div>

well so you wanna return enum without know what enum is that?  
thats impossible i thinkbecause compiler need to know what he need return unless you return UENUM…

You can return enum from string but you need to know exactly what enum type you want back or you can get any enum as byte.

---

<div class="post-metadata">

**Author:** ![AmphDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AmphDev](https://forums.unrealengine.com/u/AmphDev)\
**Post date:** [February 28, 2018, 6:10pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/8 "2018-02-28T18:10:18Z")

</div>

but you can try this:

```
      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));

```

source: [Conversion of Enum to String - C++ - Unreal Engine Forums](https://answers.unrealengine.com/questions/330496/conversion-of-enum-to-string.html)

This will return name as string without knowing the real enum, but not the enum type…

---

<div class="post-metadata">

**Author:** ![DaDummy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaDummy](https://forums.unrealengine.com/u/DaDummy)\
**Post date:** [February 28, 2018, 7:06pm UTC](https://forums.unrealengine.com/t/tnameof-does-not-work-for-uenums/418506/9 "2018-02-28T19:06:19Z")

</div>

Thank you for your suggestion, but once I have the stringified typename I’m already done with regard to this question. I’m looking for a way to ask the Unreal reflection system for the stringified name of a given actual type.

In other words: I do **have**

```
EMyUEnumType

```

and I **want**

```
FName(TEXT("EMyUEnumType"))

```

And I want to achieve this without macros on my side or entering the string myself. TNameOf looks like a template meant to achieve just that, but it seems not to work as I expected in current engine versions.
