Enum in separate files

Hi,

i introduced an ENUM in my project in a separate .h - file, called “Eventnames.h”. I added it in VS via the “Add new item” window as normally.



#pragma once

UENUM(BlueprintType)
enum class EEventNames : uint8
{
   FROM_UI_SEND_TEXTFIELD_VALUE,
   FROM_UI_SEND_VECTOR_VALUE,
   FROM_UI_SEND_SLIDER_VALUE,
   FROM_UI_SEND_TOGGLE_VALUE
};

This worked. In the class which uses the Enum it was imported with #include “Ui/EventNames.h”.

As the project grows, so did the needed Enums and i introduced more Enums and more files.

At some point the Compiler complains about that it does not now BlueprintType and stuff.



\Public\Ui/EventNames.h(3): error C2065: 'BlueprintType': undeclared identifier
\Public\Ui/EventNames.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
\Public\Ui/EventNames.h(4): error C2059: syntax error: 'enum [tag]'
\Public\Ui/EventNames.h(4): error C2059: syntax error: 'function-style cast'
\Public\Ui/EventNames.h(5): error C2143: syntax error: missing ';' before '{'
\Public\Ui/EventNames.h(5): error C2447: '{': missing function header (old-style formal list?)


I could not figured out whats the problem, because if i copy-paste the ENUM(s) from the files and pasted it in the Class-Header it instantly worked again.

Are there some recommendations when using ENUMs in separate files ?

Thank you in advance.

Seim

You don’t have a semicolon at the end of you enum.

Ups, yes this is true, but this is not the cause of the bug; I only forgot to copy paste it in the form above.

EventNames.h


#pragma once

#include "CoreMinimal.h"
#include "**EventNames**.generated.h"

UENUM(BlueprintType)
enum class EEventNames : uint8
{
FROM_UI_SEND_TEXTFIELD_VALUE,
FROM_UI_SEND_VECTOR_VALUE,
FROM_UI_SEND_SLIDER_VALUE,
FROM_UI_SEND_TOGGLE_VALUE
};

Damnit. How could i overlook this ! :slight_smile: Thank you Solid Sk, this was the exact missing piece i needed.
I only wonder WHY it worked before without inlcuding anything.

Adding Via “Add new Item” isn’t working for me.

When ever I add .h file for my enum and upon generating Visual Studio Project files it removes the enumTest.h file automatically.

I create the .h via Windows Explorer, open it in Notepad++, copy/paste and edit as necessary then generate Visual Studio Project Files.

I have never used VS to create the files. If I don’t use the editor, I do it manually as above.