# How To use An enum as a string

**URL:** <https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [August 6, 2023, 4:38pm UTC](https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693 "2023-08-06T16:38:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![omerdemirci](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@omerdemirci](https://forums.unrealengine.com/u/omerdemirci)\
**Post date:** [August 6, 2023, 4:38pm UTC](https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693/1 "2023-08-06T16:38:28Z")

</div>

Hello, I wanted to use datatable so I created UStruct and datatable. All of them is working well but there is just one issue. While using FindDatatableRow, I want to pass an enum to function as a string. What I mean, normally FindDatatableRow takes argument as an string to determine which row to find. Instead of writing a string, I want to pass an enum that stores some names matching the rows. Is it possible? My goal is creating basic Rock Paper Scissors game. Datatable will store all mesh for all character. I will edit its enum via editor and its automaticly change properties according to correspoding row.

```auto
table = data->FindRow<FRtable>(FName("abc"), FString("asd"));

```

```auto
ENUM()
enum choose{
	rock
	paper
	scissors

};

```

````auto
USTRUCT()
struct FRtable : public FTableRowBase {
	GENERATED_BODY(BlueprintType)
		UPROPERTY(EditAnywhere)
		UStaticMesh* rmesh; // it will be change according to chracter 
	UPROPERTY(EditAnywhere)
		FName pointp;if my chracter is rock this will be scissors
	UPROPERTY(EditAnywhere)
		FName pointS; //if my chracter is rock this will be papaer
	UPROPERTY(EditAnywhere)
		FName pointEq; if my chracter is rock this will be rock

};```

I want to placed an enum to "abc"
````

---

<div class="post-metadata">

**Author:** ![Bojann](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bojann/32/906560_2.png) [@Bojann](https://forums.unrealengine.com/u/Bojann)\
**Post date:** [August 6, 2023, 4:53pm UTC](https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693/2 "2023-08-06T16:53:12Z")

</div>

I am no sure I understood your question good, but I’ll try to help nevertheless. There are two approaches to this.

1. Use UEnum::GetValueAsString(your\_enum\_reference)

2. Create translator method  
.h file

Use UEnum and Mind Unreal Engine Naming conventions. Also, please name it to something more logical than “Choose” 😃

```auto
UENUM()
enum EChoose {
	Rock,
	Paper,
	Scissors,
};

FString GetMyEnumValue(EChoose MyEnum) const;

```

Then

.cpp

```auto
FString YourClass::GetMyEnumValue(EChoose MyEnum) const
{
	switch (MyEnum)
	{
		case Rock: { return "Rock"; }
		case Paper: { return "Paper"; }
		case Scissors: { return "Scissors"; }
		default: { // handle error or return some default value }
	}
}

```

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [August 6, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693/3 "2023-08-06T16:55:17Z")

</div>

> [@Bojann](#):
>
> - UEnum::GetValueAsString(your\_enum\_reference)

Given that the Unreal Header Tool already generates the translation table in question, re-implementing it yourself in a header/CPP file seems like un-needed work 🙂  
You should just use the built-in function!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 5, 2023, 4:55pm UTC](https://forums.unrealengine.com/t/how-to-use-an-enum-as-a-string/1252693/4 "2023-09-05T16:55:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
