Need Help: How can I create (Multiple) Enums inside single Cpp. class?

I tried to create a CPP class with multiple Enumerators. But I got across multiple errors and I have no idea how to solve them.


Not to act unprofessional: Don’t tell me “nothing’s wrong” with my code, because the Error List tells for itself.

one problem is UPROPERTY can not be used outside of a class/struct
just making a global UPROPERTY will not work like this

another one is that it looks like the generated.h file has not been created, try rerunning the generate visual studio project files function

small tip on the side, paste the code as preformatted text, easier to read than a screenshot

Kinda figured out how to make Enums on my own.
#include "Engine/Blueprint.h" was missing.
And I didn’t needed UPROPERTY and EnumAsByte to expose this to Variables.

Now… how can I add the Enum from CPP. as a variable to the structure…

you don’t need to include Blueprint.h, and you most definitely shouldn’t include another file’s generated file in a .h

Also, you should use enum class ECndCostumePart : uint8 instead of plain enum

You see, in my case for my cpp Enums, I have to. Otherwise, I get this:

Plus I’m trying to add my Enum to the structure inside my CPP. Just… don’t know how, and I thought adding it to includes of GD_DataRow_CndTalk would be it.


if you have a file with just enums, you cannot include a .generated.h file, since enums don’t have generated files

As far as I know only if a GENERATED_BODY macro is in the document do you need to include the .generated.h file

This works just fine

image
image
image

Late response. Took a while to figure it out couple of things.

So first: Making Multiple Enums, inside single cpp. class. I only need a header file to create simple enums. I don’t need to #include anything in them.

// First Enumerator
UENUM(BlueprintType)
enum EMyFirstEnum
{

EnumValue00_Start,
EnumValue01,
EnumValue02,
EnumValue03_Final

};


// Second Enumerator
enum EMySecondEnum
{

EnumValue00_Start,
EnumValue01,
EnumValue02,
EnumValue03_Final

};

Second: If I want to make variable, using this enum, to my structure inside my GD_DataRow file, I do this:

I add the CPP. class that has my enums to my DataRow cpp. (header h.) class by using: #include "Enums_MyEnums.h"

In total, all these includes:

#include "CoreMinimal.h"
#include "Engine/DataTable.h"
#include "Enums_MyEnums.h"
#include "GD_DataRow_MyStructure.generated.h"

Then do this inside my (one and only) header file of GD_DataRow with multiple structs:


USTRUCT(BlueprintType)
struct FGD_DataRow_MyStructure : public FTableRowBase
{
    GENERATED_BODY()

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TEnumAsByte <EMyFirstEnum> VariableName;
};

By including : public FTableRowBase I’m making this struct visible in Pick Row Structure window.

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