How can I use a UENUM as a TArray type element?

I have a UENUM I would like to use as the type for a TArray. However, attempting this produces a compiler error which I can’t wrap my head around.

This is the function in question:

void AGameCharacter::RenderTypes(TArray< EGameEquipmentDisplayType > Types, bool bShouldRender)
{
	for (int i = 0; i < Types.Num(); ++i)
	{
		switch (Types[i])
		{
			case EGameEquipmentDisplayType::EQD_SmallBoots:
				if (bShouldRender)
				{
					RenderElement(SmallBootsTextureElement, true);
				}
				else
				{
					RenderElement(SmallBootsTextureElement, false);
				}
				break;
//and so on for a lot of enum elements

The error which the compiler throws is this:

1>f:\unreal engine\unreal projects\GameProject 4.6\source\GameProject\GameCharacter.h(28): error C2664: 'void AGameCharacter::RenderTypes(TArray<EGameEquipmentDisplayType,FDefaultAllocator>,bool)' : cannot convert argument 1 from 'TArray<TEnumAsByte<EGameEquipmentDisplayType>,FDefaultAllocator>' to 'TArray<EGameEquipmentDisplayType,FDefaultAllocator>'

1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

1>F:\Unreal Engine\Unreal Projects\GameProject 4.6\Source\GameProject\GameCharacter.h(28): error C2664: 'void AGameCharacter::RenderTypes(TArray<EGameEquipmentDisplayType,FDefaultAllocator>,bool)' : cannot convert argument 1 from 'TArray<TEnumAsByte<EGameEquipmentDisplayType>,FDefaultAllocator>' to 'TArray<EGameEquipmentDisplayType,FDefaultAllocator>'

1>          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

I’m not getting anywhere with this. Any help will be greatly appreciated.

How did you declare the enum?

If you used the default way, maybe you should declare:

TArray< EGameEquipmentDisplayType::Type > Types,

My enum is declared like this:

UENUM(BlueprintType)
enum class EGameEquipmentDisplayType : uint8
{
	EQD_None			UMETA(DisplayName = "None"),
	EQD_SmallBoots		UMETA(DisplayName = "Small Boots"),
	EQD_MediumBoots		UMETA(DisplayName = "Medium Boots"),
	EQD_MediumBootsAlt	UMETA(DisplayName = "Medium Boots Alternate"),
	EQD_LargeBoots		UMETA(DisplayName = "Large Boots"),
	EQD_HugeBoots		UMETA(DisplayName = "Huge Boots"),
	EQD_SmallTrousers	UMETA(DisplayName = "Small Trousers"),
	EQD_MediumTrousers	UMETA(DisplayName = "Medium Trousers"),
	EQD_LongShirt		UMETA(DisplayName = "Long Shirt"),
	EQD_LongDress		UMETA(DisplayName = "Long Dress"),
	EQD_ShortShirt		UMETA(DisplayName = "Short Shirt"),
	EQD_LongSleeves		UMETA(DisplayName = "Long Sleeves"),
	EQD_PuffySleeves	UMETA(DisplayName = "PuffySleeves"),
	EQD_BigBracers		UMETA(DisplayName = "Big Bracers"),
	EQD_TinyCloak		UMETA(DisplayName = "Tiny Cloak"),
	EQD_SmallCloak		UMETA(DisplayName = "Small Cloak"),
	EQD_MediumCloak		UMETA(DisplayName = "Medium Cloak"),
	EQD_MediumCloakAlt	UMETA(DisplayName = "Medium Cloak Alternate"),
	EQD_LongCloak		UMETA(DisplayName = "Long Cloak"),
	EQD_BigBelt			UMETA(DisplayName = "Big Belt"),
	EQD_SmallGloves		UMETA(DisplayName = "Small Gloves"),
	EQD_LargeGloves		UMETA(DisplayName = "Large Gloves"),
	EQD_Tabard			UMETA(DisplayName = "Tabard")
};

Unfortunately, I can’t directly select one of the enum types, as I need the array to be able to hold different values (such as EQD_SmallTrousers and EQD_PuffySleeves) at the same time.

  1. Make sure you have included the file containing the UENUM
    2. Try changing TArray for TArray<TEnumAsByte>
    3. If all not work, use uint8 in your array and cast back to EGameEquipmentDisplayType.
  1. Make sure you have included the file containing the UENUM
    2. Try changing TArray for TArray<TEnumAsByte>
    3. If all not work, use uint8 in your array and cast back to EGameEquipmentDisplayType.

My enum is properly included. How would I do 2)?
3), as you can see in my comment above, is how I am doing it.

This is still an issue.

Scratch that, I changed my TArray to this instead:

TArray TEnumAsByte EGameEquipmentDisplayType

this sounds like it would be alot of work to add new entries to that enum, you would have to update its rendering switch/case entry as well.

why not just use an array of structs, where each struct contains a name and a reference to a texture element? then your render code could be generic, so it doesn’t need to be updated for every entry.