Suppose I have some arbitrary enum, and I’m trying to generate a random value from it. It’s trivial to accomplish this with a static cast and a hardcoded random int:
However, this requires me to keep excruciating track of every place I use this logic in, and manually change the range I feed FMath whenever I modify the enum. Is there any way I can manually check the exact number of possible values an enum has, instead of hard-coding it every time?
I’m kind of surprised by this- I know UE1-3 had something called EnumCount, but intellisense doesn’t recognize this in 4 and I can’t find a reference to it in the API.
And that’s all you have to call when you need a random EColor::Type. When ever you add/remove values to/from namespace EColor, then you only need to update Color_Count.