Any way to do this in BP’s?
I can not find anything for this specifically. Perhaps convert it to an array then go from there, but that seems hackish.
Any way to do this in BP’s?
I can not find anything for this specifically. Perhaps convert it to an array then go from there, but that seems hackish.
Just do ‘Get Number of Entries in MY_ENUM’.
Or you can do Blueprint equivalent of something like
I don’t think that there is anything like that, every conversion just converts the current value, seeing as there is no sort of lastItem call. Now that I think of it, you might be wanting to do this for a dynamic enum, if that’s the case, you’ll need to convert it to an array, and then get the length.
Yeah convert to array and then array -> length seems to be it.
Just fyi, in the BP right click menu, type in the name of your array you will see a Get number of entries of <your enum name>. Confirmed it works in 4.10.4
Exactly what I needed. Just start typing “Get number of entries” and pick your enum from the list and it spits out an integer. Perfect!
Enums are considered as bytes so you can have the last entry in your enum be “MAX” and just get the byte value of MAX - 1
How? What node is that? I can not for the life of me find how to do that in BPs.
Very late response to the thread, but you can get this information through the UEnum field object.
UEnum* UMyFunctionLibrary::GetEnumFieldObject(const FString& enumName)
{
[INDENT=2]return FindObject<UEnum>(ANY_PACKAGE, *enumName);[/INDENT]
}
Example Usage:
UEnum* enumObj = UMyFunctionLibrary::GetEnumFieldObject(“EGetWorldErrorMode”);
int64 maxVal = enumObj->GetMaxEnumValue();
You can also use this for other things, such as to convert the current value of an enum into its string representation:
EGetWorldErrorMode errorMode = EGetWorldErrorMode::Assert;
FString enumString = enumObj->GetNameStringByIndex((uint32)errorMode);
Hope that helps anyone viewing this in the future!
Not sure if it’s a new thing, but this works.
(int32)StaticEnum()->GetMaxEnumValue();
Yeah…
This solution is the best.
Just type “Get numer of entries in *****” - where ***** is the name of your enumeration!
Thanks for this hint…
This works great in UE 5.1, thanks!
Still works in 5.4, thank you so much, I would never have found that get entries node <3
In C++ it should be StaticEnum<EMyEnum>()->NumEnums() - 1
.
GetMaxEnumValue()
won’t return correct result if you ever set arbitrary value on the enum element.