UEnum : how to query the FString value at index?

Hi,
I’m currently learning how to use UEnum and so I followed Rama’s example:

UENUM(BlueprintType)		//"BlueprintType" is essential to include
enum class EVictoryEnum : uint8
{
        VE_Dance 	UMETA(DisplayName="Dance"),
        VE_Rain 	UMETA(DisplayName="Rain"),
	VE_Song	UMETA(DisplayName="Song")
};
 
UCLASS()
class YourClass : public YourSuperClass
{
	GENERATED_UCLASS_BODY()
 
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Enum)
	EVictoryEnum VictoryEnum;
 
	//Rest of Class Code
};

I’m currently investigating how I would get the FString at index[i] and again using Rama’s example:

FString GetVictoryEnumAsString(EVictoryEnum::Type EnumValue)
{
  const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EVictoryEnum"), true);
  if(!EnumPtr) return FString("Invalid");
 
  return EnumPtr->GetEnumName(EnumValue); // for EnumValue == VE_Dance returns "VE_Dance"
}

I assumed the EVictoryEnum::Type EnumValue was where I would pass in a uint8 to check the index, but my compiler won’t have any of it, saying that ‘EVictoryEnum’ has no member type ‘EnumValue’ which I understand, but why is the example written this way?? Is there something interesting going on in the method definition in the .h file I’m missing?

Hello,

From the way method is declared, I assume it is supposed to be used with old enums. For example, the old-style declaration for described enum would look like this:

UENUM(BlueprintType)
namespace EVictoryEnum 
{
	enum Type 
	{
		VE_Dance   UMETA(DisplayName = "Dance"),
		VE_Rain    UMETA(DisplayName = "Rain"),
		VE_Song    UMETA(DisplayName = "Song")
	};
}

In the declaration you would need to use TEnumAsByte:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Enum)
TEnumAsByte<EVictoryEnum::Type> VictoryEnum;

However, to get the method work with the new-style enum that is provided in the tutorial, you can replace EVictoryEnum::Type EnumValue in the argument list with uint8 EnumValue:

FString GetVictoryEnumAsString(uint8 EnumValue)

If you like to learn more about enums in Unreal Engine 4, please go here:

Hope this helped!
Cheers!

Ahhh I am going to try this, but that makes sense. I had a feeling it may have been for an older style enum. Thanks for the info and the doc link!

@.Bulgakov : I tried this implementation, so in blah.h I have:

    //header stuff
    UENUM( )
    enum class ETaxiMoveModeEnum : uint8
    {
    	TX_PerchedIdle 	UMETA( DisplayName = 'Perched - Idle' ) ,
    	TX_Flapping 	UMETA( DisplayName = 'Flapping' ) ,
    	TX_Diving		UMETA( DisplayName = 'Diving' ) ,
    	TX_Gliding		UMETA( DisplayName = 'Gliding' )
    };
    //...
    UCLASS(Blueprintable)
    class AtwinStickPawn : public APawn
    {
    	GENERATED_BODY()
    
    	UPROPERTY()
    	ETaxiMoveModeEnum ETaxiMovementModeObj; 
    //... etc etc

and then in the blah.cpp I am trying to access the enum values via:
AtwinStickPawn::AtwinStickPawn(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{ 
//...
ETaxiMoveModeObj::TX_Flapping 

but I get an error saying:
ETaxiMoveModeObj is not a namespace or class. Which I guess is pretty obvious looking at it. So just how am I to access this enum data?