# Adding ToString to a custom Enum?

**URL:** <https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 1, 2014, 2:18pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204 "2014-05-01T14:18:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byorun\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Byorun\_1](https://forums.unrealengine.com/u/Byorun_1)\
**Post date:** [May 1, 2014, 2:18pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/1 "2014-05-01T14:18:16Z")

</div>

I am trying to add a ToString function to my custom Enum in C++ because if I use Blueprints I can convert my custom enum to string. C++ the only way I found from other header files was like this (without the UENUM macro)

```
UENUM(BlueprintType)
namespace EKaoriGameUnit
{
	enum Type
	{
		Alive	UMETA(DisplayName = "Alive"),
		Dead	UMETA(DisplayName = "Dead")
	};

	inline const TCHAR* ToString(EKaoriGameUnit::Type State)
	{
		switch (State)
		{
		case Alive:
			return TEXT("Alive");
		case Dead:
			return TEXT("Dead");
		}
		return TEXT("Unknown");
	}
}

```

Since I want to use this or other Enums later in Blueprints I added the UENUM macro but now the UHT throws this error

> KaoriGameTypes.h(10): error : In TemporaryUHTHeader\_KaoriGameTypes: Missing ‘}’ in ‘Enum’

---

<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:** [May 1, 2014, 3:40pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/2 "2014-05-01T15:40:23Z")

</div>

#Alternative / Skip a Step

If you are willing to try an alternative you can make a BlueprintFunctionLibrary for yourself that will do the same as your function does.

Keep in mind blueprint function libraries can be used anywhere! Even in anim blueprints! anywhere!

so it is not that much of an issue 🙂

You’re just declaring the enum strings in a different but absolutely **blueprint global** context

* * *

I think of this as skipping a step because you’d need to write up some sort of BP interface for your proposed Enum function anyways. But now it is instantly BP global and you dont have to write it twice

* * *

You can also use the static blueprint functions **in any .cpp file** like any other static library functions

#Wiki

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

🙂

Rama

---

<div class="post-metadata">

**Author:** ![Byorun\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Byorun\_1](https://forums.unrealengine.com/u/Byorun_1)\
**Post date:** [May 1, 2014, 3:49pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/3 "2014-05-01T15:49:14Z")

</div>

That is definitely something to consider at a later point thanks, but for now I need a way to get the Text representation for my enum. What I did in Blueprints was searching the level for camera actors (I tagged them with a specific text value) belonging to the team of the player.  
I was trying the same in C++ but there is no function to convert an Enum value to string ☹

---

<div class="post-metadata">

**Author:** ![Marc\_Audy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marc_audy/32/710746_2.png) [@Marc\_Audy](https://forums.unrealengine.com/u/Marc_Audy)\
**Post date:** [May 1, 2014, 7:26pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/4 "2014-05-01T19:26:58Z")

</div>

The UENUM parsing of a namespace gets rather cranky if you have something other than just the Enum in it. You can do this instead to get the same behavior in terms of the namespacing but with functional compiling!

```
UENUM(BlueprintType)
namespace EKaoriGameUnit
{
	enum Type
	{
		Alive	UMETA(DisplayName = "Alive"),
		Dead	UMETA(DisplayName = "Dead")
	};
}

namespace EKaoriGameUnit
{
	inline const TCHAR* ToString(EKaoriGameUnit::Type State)
	{
		switch (State)
		{
		case Alive:
			return TEXT("Alive");
		case Dead:
			return TEXT("Dead");
		}
		return TEXT("Unknown");
	}
}

```

To get your enum to string in a less switchy manner:

```
FindObject<UEnum>(ANY_PACKAGE, TEXT("EKaoriGameUnit"), true)->GetDisplayNameText(State);

```

---

<div class="post-metadata">

**Author:** ![Byorun\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Byorun\_1](https://forums.unrealengine.com/u/Byorun_1)\
**Post date:** [May 1, 2014, 8:35pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/5 "2014-05-01T20:35:10Z")

</div>

Thank you. That works perfect 🙂

---

<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:** [May 1, 2014, 9:56pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/6 "2014-05-01T21:56:46Z")

</div>

#Thank You Marc!

wow that’s awesome Marc!

Thanks!

#Added to Wiki

I added your awesome get Enum as String function to the Wiki!

> **[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:** ![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:42pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/7 "2014-07-17T20:42:49Z")

</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:** ![Pelangi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pelangi](https://forums.unrealengine.com/u/Pelangi)\
**Post date:** [August 14, 2016, 11:08am UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/8 "2016-08-14T11:08:34Z")

</div>

What if the enum text (to be displayed) should be different than the enum values? For example:

```
enum Type
{
EType1,
EType2
}

```

If I want to print the text version of EType1 into “Alive” and EType2 into “Dead”, then your posting on Wiki won’t work. Do you have another Wiki which can do what I explain here?

---

<div class="post-metadata">

**Author:** ![John\_Ladon\_Smith](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@John\_Ladon\_Smith](https://forums.unrealengine.com/u/John_Ladon_Smith)\
**Post date:** [January 28, 2025, 5:08pm UTC](https://forums.unrealengine.com/t/adding-tostring-to-a-custom-enum/282204/9 "2025-01-28T17:08:02Z")

</div>

```auto
UENUM(Blueprintable, BlueprintType)
enum class EMissionRewardType : uint8
{
    LevelUp UMETA(DisplayName = "Level Up!"),
    Point UMETA(DisplayName = "+1 Point"),
    Weapon UMETA(DisplayName = "Weapon"),
    Spell UMETA(DisplayName = "Spell"),
};

```

```auto
FText RewardDisplayName = UEnum::GetDisplayValueAsText(EMissionRewardType::Point );

```
