But is there a better way? Doing this the array would have to be generated every time and it is not static. If I have a lot of enums I would have to create a method for each one. Perhaps I need to make a templated version of it or perhaps there is already support for what I’m trying to do. My goal is to eventually just loop through all enums like so:
for (auto e : SomeEnumArray)
{
CallSomeMethod(e);
}
It’s not directly what you’re looking for, but you can achieve iteration over a given UENUM’s enumerators by using the FOREACH_ENUM_* macros. These get generated automatically for each UENUM type:
This might not be exactly what you want but you can create static arrays like this:
UENUM(BlueprintType)
namespace EObjective
{
enum Type
{
// Numeric
CaptureReactor = 0 UMETA(DisplayName = "Capture Reactor"),
CaptureFlag UMETA(DisplayName = "Capture Flag"),
PickUpReactor UMETA(DisplayName = "Pick Up Reactor"),
PickUpFlag UMETA(DisplayName = "Pick Up Flag"),
// This must always be at the end
Max UMETA(DisplayName = "Invalid")
};
}
The great thing about this way is that the Editor automatically shows the static array in a very readable way. Instead of a typical TArray where it would show