I’m using this syntax to get property editing on a fixed size array with the elements of the array displaying enum item names:
UENUM()
enum class EMyEnum : uint8
{
A, B, C, D, Max
};
UPROPERTY()
bool MyArray[EMyEnum::Max];
This works well on PC but is actually invalid c++ because EMyEnum::Max doesn’t evaluate to an integer. I’ve only just realised that this won’t compile on PS4 where the compiler is more strict.
I can get it to compile on PS4 by doing this:
bool MyArray(uint8)EMyEnum::Max];
But then the names aren’t displayed in the properties editor any more.
I’d really like to keep using enum classes as using old style enums means going back to all the problems that enum classes have been introduced to fix.
Is there any chance you can make the properties parser cope with the above cast (or a static_cast<uint8>)? Or tell me where the code I’d need to modify is to do this myself?
Or is there some other existing solution or workaround that people are using?
If it’s only complaining on use (like when you want to say print out the raw value or use it with math or whatnot) just cast it to uin8 at the spot that is needed for use.
The other option is try to use pragma ignore if the compiler will allow it (I have no idea).
Can you declare the ‘MAX’ value yourself? UHT will only create that item if it doesn’t already exist IIRC. You can use UMETA(Hidden) to hide it away from end-users.
We needed to compile for Linux, which also doesn’t work with strong-typed enum values as array sizes.
I tried pre-processor macros for different platforms and for WITH_EDITORONLY_DATA, in several ways, but UHT can’t handle them.
I didn’t want to use TMap at first because the BP developer is not supposed to be able to change they key values.
I ended up using TMap but with UPROPERTY(EditFixedSize). Then, on the class constructor, I add all enum keys and leave values as default.
On Blueprints, it looks ugly, because it feels like you can change the enum value keys and you can’t. But at least the values are “named” now. And because it’s a fixed size TMap with all possible keys already there, you can’t change any of them, as Unreal will complain that you can’t have duplicate keys.
Not as beautiful and simple as just having a fixed-size array and using the enum as index, but GCC and UHT don’t like beautiful and simple.
This was the first thread that popped up when I searched for this, so I’ll share my solution even though it’s an old thread. Managed to work around this issue using a macro hack.
yes, the “_MAX” part is mandatory, exactly as typed. That alone wouldn’t get UE to pick up the enum as index names properly, though. I’m guessing UHT is explicitly looking for the max item verbatim in the array size.