UPROPERTY on TEnumAsByte causes compile error

Hi there,

I’m getting a strange error when making a TEnumAsByte a UPROPERTY. It occurs regardless of what enum I try.

TEnumAsByte<ESomeEnum::Type> SwipeDirection;

Compiles fine, however

UPROPERTY(EditAnywhere, Category = Spell)
TEnumAsByte<ESomeEnum::Type> SwipeDirection;

Causes the following compile error

Expected the name of a previously defined enum

This only occurs in one of my classes. Which is a new empty class?

Many Thanks

If the enum is defined in another class/header-file you need to include it:

#include “path/to/your/file.h”

make sure this is before your generated header include!

Thanks for the reply. However the error occurs regardless of what enum I use. Whether it be a custom or engine based.

e.g. EAcceptConnection causes the crash as well as any custom one I try.

Every enum you use, if it is not declared in the same header file you are using it, you need to include the header file it is defined in!

edit: okay, nevermind if this also happens to the engine based this is wired…

Just a guess, but what happens if you remove the ::Type after the namespace?

I have a header containing a bunch of enums, structs etc. This is where the enum is I want to use. However this header includes the class itself (as it’s referenced in one of the structs). So importing it into the class causes a circular reference.
However even with an engine enum such as EAIForceParam and including AITypes.h (where it’s located) causes the error.

I’m pretty new to C++ and been awake for 24 hours so bear with me here :slight_smile:

No difference :frowning:

You should define it inside a new header to prevent those circular references. But that wont fix the problem…

My enums usually also have the BlueprintReadOnly parameter for the UPROPERTY:

UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Item Attachment")
TEnumAsByte<EHandSlot::Type> UsesHands;

maybe this helps, but i doubt it.

Oh, and also make sure for the Enums you use that there is:

UENUM(BlueprintType, Category = “”)

defined above it, just in case you do not already have it :slight_smile:

You need to use forward declarations, since your compiler is runnning into circular dependencies and to avoid that your compiler skips the include to not to be included again thanks to the #pragma once macro

You need to move your include directives in to the CPP file and in your include use forward delcrations.

I had the same problem on 4.22 Unreal version.
The error: “Expected the name of a previously defined enum” isn’t caused by a missing include file because it is not a C++ compiler error but it is an Epic HeaderTool error.
Basically if you define a UENUM in a Header file without define any USTRUCT or UCLASS the HeaderTool doesn’t parse that file, so the UENUM definition will not be stored in the object hash list.

Possible solutions (until Epic GenerateProjectFiles fix)

  • Move the UENUM declaration in a Header file where there are some USTRUCT or UCLASS declaration

  • Declare a dummy struct or class like this:

    struct FDummyStruct

and launch the batch GenerateProjectFiles.bat so the HeaderTool will parse your header.


I ran into this same error today even though the syntax was correct after triple-checking it all over. I tried forward declarations and that did not work. I did notice that Visual Studio stopped colorizing the tags in my code, so I decided to try something that fixed other issues I’ve had…

If time isn’t a constraint, try:

  1. Close UE4 and Visual Studio
  2. Delete Binaries and Intermediate Folders
  3. Right-click *.uproject file and generate new Visual Studio project files
  4. Re-open UE4 and Visual Studio. Compile in Engine.

Worked for me as of 4.25.4

I’ve had this problem before because of my carelessness. You can check whether you had loss ‘UENUM()’ above The Enums you define.