UEnum in Unreal Engine 5 C++



Syntax

UENUM(BlueprintType)
enum class ECustomEnum : uint8 {
    ValueA UMETA(DisplayName="My Value 1"),
    ValueB,
    ValueC
};

Bitflag Syntax

UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true"))
enum class ECustomBitFlagEnum: uint8
{
	BitValueNone = 0,
	BitValueA = 1 << 0,
	BitValueB = 1 << 1,
	BitValueC  = 1 << 2
};
ENUM_CLASS_FLAGS(ECustomBitFlagEnum);


// Creating
ECustomBitFlagEnum MyBitFlag = ECustomBitFlagEnum::FlagA | ECustomBitFlagEnum::FlagC;

// Turning On Flag
MyBitFlag |= ECustomBitFlagEnum::FlagB;

// Turning Off Flag
MyBitFlag &= ~ECustomBitFlagEnum::FlagA;

// Checking for Flag
bool bIsFlagActive = (MyBitFlag & ECustomBitFlagEnum::FlagC) == ECustomBitFlagEnum::FlagC;