# Enum in separate files

**URL:** <https://forums.unrealengine.com/t/enum-in-separate-files/151772>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [October 7, 2020, 9:57am UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772 "2020-10-07T09:57:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seim2k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seim2k](https://forums.unrealengine.com/u/Seim2k)\
**Post date:** [October 7, 2020, 9:57am UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/1 "2020-10-07T09:57:22Z")

</div>

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.

```auto

#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.

```auto

\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

---

<div class="post-metadata">

**Author:** ![acxsasx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@acxsasx](https://forums.unrealengine.com/u/acxsasx)\
**Post date:** [October 7, 2020, 1:55pm UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/2 "2020-10-07T13:55:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Seim2k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seim2k](https://forums.unrealengine.com/u/Seim2k)\
**Post date:** [October 7, 2020, 3:43pm UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/3 "2020-10-07T15:43:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SolidSk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solidsk/32/1194513_2.png) [@SolidSk](https://forums.unrealengine.com/u/SolidSk)\
**Post date:** [October 7, 2020, 8:54pm UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/4 "2020-10-07T20:54:05Z")

</div>

_EventNames.h_

```auto

#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
};

```

---

<div class="post-metadata">

**Author:** ![Seim2k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Seim2k](https://forums.unrealengine.com/u/Seim2k)\
**Post date:** [October 8, 2020, 9:04am UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/5 "2020-10-08T09:04:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Raja.Haris](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/raja.haris/32/1191940_2.png) [@Raja.Haris](https://forums.unrealengine.com/u/Raja.Haris)\
**Post date:** [November 16, 2020, 6:07am UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/6 "2020-11-16T06:07:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![acxsasx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@acxsasx](https://forums.unrealengine.com/u/acxsasx)\
**Post date:** [November 16, 2020, 1:54pm UTC](https://forums.unrealengine.com/t/enum-in-separate-files/151772/7 "2020-11-16T13:54:56Z")

</div>

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.
