I would like to get the byte value from enum as integer for array
Initially i do thing like this, but failed:
(i have a struct with enum type)
FStructType myStruct;
uint8 bytes = myStruct.myEnum;
After done some searching i change it to this, but still failed:
struct FStructType{
EEnumType myEnum;
UEnumAsByte<EEnumType> getEnum(){
return myEnum;
}
}
FStructType myStruct;
uint8 bytes = myStruct.getEnum();
I need some tips on conversion, please do help me in this ><"
Appreciate for those who willing to help.
Can we see the definition for EEnumType?
MickD777
(MickD777)
3
If I’m not mistaken, simply “hard” casting it should work.
//Have you tried that?
uint8 bytes = (uint8)myEnum;
mirsabayu
(mirsabayu)
4
is it TEnumAsByte ?? what is UEnumAsByte??? (but you don’t need it if you use class enum)
Hi,
You forgot set semicolon for complete your struct definition; also you should initialize myEnum value before using it.
Line
uint8 bytes = myStruct.myEnum;
Should work if you declare your enumeration like enum EEnumType. If you use enum class then change it to:
uint8 bytes = (uint8)myStruct.myEnum;
Hope it helps!
1 Like
Thx for reminding me that my struct is missing a semicolon and your solution
I had tried many ways to convert an enum to byte, except your method
Your solution is working fine now ^^
Big Thx!!
Yeah this answer is the same as Bulgakov
UENUM(BlueprintType)
enum class EArmorType : uint8{
//UMETA is to enable blueprint switch function
EHelmet UMETA(DisplayName = “Helmet”),
EChest UMETA(DisplayName = “ChestPlate”),
EGlove UMETA(DisplayName = “Gloves”),
EPant UMETA(DisplayName = “Pant”),
EShoes UMETA(DisplayName = “Shoes”)
};
Im not sure is TEnumAsByte or UEnumAsByte???(Forget where i get this from)
But the method below do suite what i need
tq for replying