Array of values based on an enum

I’m trying to make a data table with an array of floats based on an enum size. Let me explain. I have damage types:

enum class EDamageTypes : uint8
	DT_None							UMETA(DisplayName = "None"),
	DT_Fire							UMETA(DisplayName = "Fire"),
	DT_Lightning					        UMETA(DisplayName = "Lightning"),


This displays just fine in the editor and blueprints and such. I want to have what is essentially a TMap or TArray of TPairs that has the element type and a float value associated with it (for amount of damage and amount of resistances and whatnot). However, TMaps and TPairs are not supported by UPROPERTY.

struct FTestArrayStruct : public FTableRowBase

	UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<TPair<EItemTypes, float>> testArray;

That leads to a compilation error, as does a TMap, saying only UCLASS, USTRUCT or UENUM types are accepted.

Going forward, I see two options:

  1. Simply make it an array and add in the values as needed, 0 values for those before the index of the desired damage type. This could lead to some messy complications if put in the wrong spot and some wild errors in damage calculations.

  2. Make a USTRUCT that contains the Enum and the float value and have an array of those. But then if I wanted other enums for the same use, I’d have to make another struct for them.

Does anyone see a solution that I’m missing?

Further testing has concluded that sadly, neither macros nor templates can accomplish what I want…

#define MAKE_ENUM_VALUE_STRUCTURE(StructName, EnumType, EnumName, ValueType, ValueName) \
USTRUCT(BlueprintType) \
struct StructName \
{ \
	UPROPERTY(EditAnywhere, BlueprintReadWrite) EnumType EnumName;\
	UPROPERTY(EditAnywhere, BlueprintReadWrite) ValueType ValueName;\
	StructName(){EnumName = (EnumType)0;}\

MAKE_ENUM_VALUE_STRUCTURE(FTestEnumValueStruct, EItemTypes, itemType, float, amount)

template<class EnumClass, class ValueType>
struct FEnumStruct : public FTableRowBase
	UPROPERTY(EditAnywhere, BlueprintReadWrite) 
	EnumClass enumValue;
	UPROPERTY(EditAnywhere, BlueprintReadWrite) 
	ValueType value;
	//UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<TPair<EItemTypes, float>> testArray;
	FEnumStruct() {}

Both of those result in compilation errors, even with the included “Filename.generated.h” file.

The macro version gives an error giving the line number of the calling of the macro, saying GENERATED_BODY() is undefined. So, I’m assuming that the unreal engine does something based off of the text in the actual file, not accounting for macros. I even tried to trick it a little by splitting up the macro into two parts, one above the GENERATED_USTRUCT_BODY() line, and one below it, so it might’ve recognized the line as being there without the defining body around it, but no good.

The templated version gives an error saying “Missing ‘struct’ in Struct declaration specifier.” (I even tried switching the template and USTRUCT lines, which results in further errors).

So, I’m back to square one… making the struct by hand. Oh wells.

struct FMyEnumStruct

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
	EMyEnum key;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
	FMyType value;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
TArray<FMyEnumStruct> enum_struct;

You can’t use your own macros with macros and structures where used this macros for reflection system. It’s part of UnrealHeaderTool. You prevent the program.

And templates can’t be used. Only pure USTRUCTs without anything foreign macros and templates.

You can wrote your own wrapper with TArray UPROPERTY inside to manage data type by enum value indexing.