How do I format enums in a CSV/datatable?

I have some enum of arbitrary length-

enum class ESomeEnum : uint8 {

In code, I can create a reference to my value type via ESomeEnum::FirstValue, but if I want to use values for my enum in an excel spreadsheet that I import as a datatable, how do I need to format them? Is there some way I can just write “FirstValue” and convert string-enum or something?

Unfortunately in C++ you cannot do it - unlike in Java where you can initialize enums with Strings,etc. What I recommend is:

static const std::pair<FString, uint8> FirstValue;
static const std::pair<FString, uint8> SecondValue; 
(and so on...)

Then initialize them:

const std::pair<FString, uint8> FirstValue = std::make_pair(FString("FirstValue"), 1);
const std::pair<FString, uint8> SecondValue = std::make_pair(FString("SecondValue"), 2);

And then you can compare them with other strings, initialize them based on strings (so a lookup, which is pretty nice), and to store them in the CSV, just access member “first”, which is the FString identifier.

Ooh that works, thank you! :slight_smile:

Oh and if you need more than just a pair - a wider collection of data - you can use tuple.


In either case, make sure to:

 #include <utility>

That’s super-helpful, thank you :slight_smile:

Enum values as names works in CSV out of the box. Here’s the example:

// Enum definiton
enum class EMyEnum : uint8
    FirstValue, SecondValue, ThirdValue

// Data table row definition
struct FMyEnumDataRow : public FTableRowBase

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	EMyEnum EnumValue;

// CSV file

Oh hey, thank you!!

Do I need any specific #includes to inherit from FTableRowBase? Right now it tells me " ‘FTableRowBase’: base class undefined," which I assume just means I need to include an extra header file.

Edit: Oh, looks like it’s #include “Engine/DataTable.h” … thank you again! :slight_smile: