Use Enums made in-engine inside code?

Hello everyone,

I’ve created an Enum inside the engine and I want to read it in my code… How can that be done?

This is what I currently have, based on a lot of googling. It does not work:

UEnum* ClothingCategoryEnum = FindObject<UEnum>(ANY_PACKAGE, TEXT("/Game/Content/GameContent/ClothingCustomization/E_ClothingCategory.E_ClothingCategory"), true);

There are some older posts that say that it’s impossible. But those are from ye olde UE4 days, perhaps I am being foolhardy in considering this, but maybe the engine has evolved and improved enough since those times of old to allow things created by the engine to be read by the code that the engine executes.

I’m hoping to not have to delete my enum and make one in code to replace it. I have a lot of blueprints that are using that enum, and a deadline over my head that is hanging like a guillotine.

Not only that, but it’s kind of impossible for me to even remove the enum any way, since it is used by a data table that my code is also accessing. Each row uses the enum to classify the item type, which I read to figure out where to place the item. The name of the enum is also read, since it corresponds to the name of a skeletal mesh child.

I’ve tried a lot of things over the last few days. None of it worked.

For the record, I have also tried:

#include "Engine/UserDefinedEnum.h"

UUserDefinedEnum* ClothingCategoryEnum = LoadObject<UUserDefinedEnum>(nullptr, TEXT("/Game/Content/GameContent/ClothingCustomization/E_ClothingCategory.E_ClothingCategory"));

It does not work.

I had forgotten that for technical documentation, the Chinese Unreal Engine developer community is years ahead of anything else.

It took a lot of translating random, obscure pages, but it seems like “content” is implied in the file path. This is silly, since “game” is not implied. But it seems to actually work:

UUserDefinedEnum* ClothingCategoryEnum = LoadObject<UUserDefinedEnum>(nullptr, TEXT("/Game/GameContent/ClothingCustomization/E_ClothingCategory.E_ClothingCategory"));

I’m not entirely certain, because I’m nothing some errors related to parsing the names of the enums, so it could be that I’m not getting an error because it technically loaded something (nothing).
Either way, it is refreshing to see a new error. I’ll keep testing and poking to see if this is indeed the correct solution or not.

Here’s a quick but not very elegant way.

If you do get the value of an “Blueprint Enum” variable, you will need to use a UEnumProperty or FEnumProperty.
Here’s about it.

I’m 55% sure this is the correct answer. Can’t tell since the rest of my code is broken, and will probably remain that way for a while. But I think it probably works.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.