Developer Notes

For internal engine purposes UnrealHeader tool adds an additional enum entry "EnumName_MAX" to the enum values, hence the runtime version returns different number.

Description

A user reported that UEnum::NumEnums appears to be returning one more than the actual number of elements in the enum.

Steps to Reproduce
  1. Create a new code project using the first person template.
  2. Add a new code class to the project derived from UObject. Name the class MyEnumObject
  3. Close the Editor.
  4. In the header file for the new class, create the following enum:
    UENUM(BlueprintType)
    enum class EEnumExample : uint8
    {
    	EE_Dance	UMETA(DisplayName = "Dance"),
    	EE_Rain		UMETA(DisplayName = "Rain"),
    	EE_Song		UMETA(DisplayName = "Song"),
    };
    
  5. In the default character class source file for the project, add the following includes:
    #include "MyEnumObject.h"
    #include "Engine.h"
    
  6. In the constructor for the default character class, add the following lines of code:
    int32 NumberOfEnums = 0;
    
    UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EEnumExample"), true);
    
    NumberOfEnums = EnumPtr->NumEnums();
    
    if (GEngine)
    {
    	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(NumberOfEnums));
    }
    
  7. Build the project in Visual Studio.
  8. Open the project in the Editor.
  9. Start PIE.

RESULT:
The number "4" is output in the top left corner of the screen.

EXPECTED:
The number "3" is output in the top left corner of the screen.

Have Comments or More Details?

Head over to the existingAnswerHub thread and let us know what's up.

0
Login to Vote

By Design
ComponentCore
Affects Versions4.6.14.8
CreatedJan 6, 2015
ResolvedJan 8, 2015
UpdatedFeb 5, 2017