# How to create a globally-available enum?

**URL:** <https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [June 9, 2014, 5:41pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799 "2014-06-09T17:41:37Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregdumb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gregdumb](https://forums.unrealengine.com/u/gregdumb)\
**Post date:** [June 9, 2014, 5:41pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/1 "2014-06-09T17:41:37Z")

</div>

Hey,

I want to create a enum that contains the different types of weapons I will have (handgun, rifle, melee, etc). But if I define this enum in the c++ weapon class, my pawn’s animation blueprint can’t access it. (I need my animblueprint to access it, because I need to have the pawn doing a different animation depending on the current weapon type.)

So where can I define an enumeration so that everything, anywhere, can see it? I’m using C++, so I can’t declare one in the content browser. I also tried declaring it in MyProject.h, but that gave me errors. (?)

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_Noland](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/michael_noland/32/1194689_2.png) [@Michael\_Noland](https://forums.unrealengine.com/u/Michael_Noland)\
**Post date:** [June 9, 2014, 6:12pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/2 "2014-06-09T18:12:33Z")

</div>

Hi Greg,

If you mark your enum declaration with UENUM(BlueprintType), then the enum should be usable in any Blueprints, including Anim Blueprints.

Cheers,  
Michael Noland

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [June 9, 2014, 6:13pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/3 "2014-06-09T18:13:57Z")

</div>

Copy and Paste the code that you put in the MyProject.h, and the errors you got.  
Are you using UENUMTYPE()?  
's a tutorial (scroll down to the C++ code): [What is proper way to make Enum for BP and C++ both - Programming & Scripting - Epic Developer Community Forums](https://answers.unrealengine.com/questions/3742/what-is-proper-way-to-make-enum-for-bp-and-c-both.html)

---

<div class="post-metadata">

**Author:** ![gregdumb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gregdumb](https://forums.unrealengine.com/u/gregdumb)\
**Post date:** [June 9, 2014, 6:43pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/4 "2014-06-09T18:43:10Z")

</div>

@Micheal Noland, yep, it shows up in blueprints now! Thanks 🙂

@jwatte, 's my GB.h code (GB is the name of my project):

[HR][/HR]  
#ifndef **GB\_H**  
#define **GB\_H**

#include “Engine.h”

#define COLLISION\_PROJECTILE ECC\_GameTraceChannel1

#endif

#include “GB.generated.h”

UENUM(BlueprintType)  
enum EItemAnimType  
{ None UMETA(DisplayName = “None”),  
Rifle UMETA(DisplayName = “Rifle”),  
Handgun UMETA(DisplayName = “Handgun”),  
Melee UMETA(DisplayName = “Melee”)  
};  
[HR][/HR]  
And I get this huge wall of errors:

c:\users\greg\documents\unreal projects\gb\intermediate\build\win64\inc\gb../…/…/…/…/Source/GB/GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\intermediate\build\win64\inc\gb../…/…/…/…/Source/GB/GB.h(26) : see declaration of ‘EItemAnimType’  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinitionc:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\>  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’ c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\>  
1\> GBUIWidget.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GBPants.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GBShirt.cpp  
1\> GBClothing.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GBBackpack.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GBWeapon.cpp  
1\> GBInventoryManager.cpp  
1\> GBInventoryItem.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinitionc:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\>  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’ c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\>  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GBProjectile.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’  
1\> GB.cpp  
1\>c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26): error C2011: ‘EItemAnimType’ : ‘enum’ type redefinition  
1\> c:\users\greg\documents\unreal projects\gb\source\gb\GB.h(26) : see declaration of ‘EItemAnimType’

Actually, it’s the same error over and over again. But how do I fix it? ☹

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [June 9, 2014, 7:02pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/5 "2014-06-09T19:02:19Z")

</div>

They are beeing redefined so if you dont have the same code in two places.  
Then your header is beeing included “twice”.

I think your issue may be the inclusion guards.  
I think i read somewhere that you need to use the visual studio one.

```auto

#pragma once

```

And it also probeboly be a good idea to create a namespace for them.

---

<div class="post-metadata">

**Author:** ![gregdumb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gregdumb](https://forums.unrealengine.com/u/gregdumb)\
**Post date:** [June 9, 2014, 7:09pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/6 "2014-06-09T19:09:45Z")

</div>

Thanks! Fixed it! I noticed that #pragma once is included in most of the source files by default, but not GB.h. Wonder why.

One more thing: is it bad to #include “GB.h” in both the .h and .cpp files for other classes? By default it’s only included in the .cpp, but I want to declare some of my custom enums in the .h.

---

<div class="post-metadata">

**Author:** ![DamirH](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damirh/32/906591_2.png) [@DamirH](https://forums.unrealengine.com/u/DamirH)\
**Post date:** [June 9, 2014, 9:45pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/7 "2014-06-09T21:45:47Z")

</div>

Heya,

Just like to pop in o share the way I handle enums and structs. This is mostly based off of a tutorial from the wiki by , so credits to him. 's my code:

```auto

#pragma once
#include "Archrune.h"
#include "Constants.generated.h"

UCLASS()
class UConstants : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()
};

#pragma region ENUMS

UENUM(BlueprintType)
namespace ELevelState
{
	enum Type
	{
		Locked,
		Open,
		Complete
	};
}

UENUM(BlueprintType)
namespace EPlayerCameraAxisState
{
	enum Type
	{
		Free,
		AttachedRelative,
		AttachedWorld
	};
}

#pragma endregion ENUMS

#pragma region STRUCTS

USTRUCT(BlueprintType)
struct FLevelStruct : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Properties")
	uint8 Level_Index;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Properties")
	FText Level_Name;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Level Properties")
	TEnumAsByte<ELevelState::Type> Level_State;
};

#pragma endregion STRUCTS

```

This allows me to have enums and structs in a single organized file, but also have a bunch of INLINE functions in the header allowing for a sort of GameUtility script. It’s really handy for keeping stuff organized.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [June 10, 2014, 9:54am UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/8 "2014-06-10T09:54:59Z")

</div>

@DamirH: This is very usefull thanks for the share it gave me some ideas as well 🙂

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [June 10, 2014, 6:50pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/9 "2014-06-10T18:50:22Z")

</div>

#pragma once is poor form.

You actually had almost the right solution already in the original file, except you had the “#endif” for the **GB\_H** in the wrong place – it should be at the end.

```auto

#ifndef __GB_H__
#define __GB_H__

#include "Engine.h"

#define COLLISION_PROJECTILE ECC_GameTraceChannel1

// #endif // this was wrong

#include "GB.generated.h"

UENUM(BlueprintType)
enum EItemAnimType
{
None UMETA(DisplayName = "None"),
Rifle UMETA(DisplayName = "Rifle"),
Handgun UMETA(DisplayName = "Handgun"),
Melee UMETA(DisplayName = "Melee")
};

#endif // this is what it should have been

```

---

<div class="post-metadata">

**Author:** ![DamirH](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damirh/32/906591_2.png) [@DamirH](https://forums.unrealengine.com/u/DamirH)\
**Post date:** [June 10, 2014, 9:45pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/10 "2014-06-10T21:45:27Z")

</div>

> [@jwatte;72691](#):
>
> #pragma once is poor form.

Not really… It’s supported by pretty much every noteworthy compiler out there today.

---

<div class="post-metadata">

**Author:** ![gregdumb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gregdumb](https://forums.unrealengine.com/u/gregdumb)\
**Post date:** [June 12, 2014, 10:39pm UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/11 "2014-06-12T22:39:19Z")

</div>

@jwatte, that actually didn’t work for me for some reason, I needed the pragma once for it to work. No matter, “pragma once” compiles, that’s good enough for me 🙂

(Sorry for late reply, internet’s been down.)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [June 13, 2014, 9:40am UTC](https://forums.unrealengine.com/t/how-to-create-a-globally-available-enum/5799/12 "2014-06-13T09:40:26Z")

</div>

The resson for this is that (and am 99.99% sure about this).  
That some where in the documentation it says NOT to use inclusion guards like #ifndef _FILE\_H_ …  
But use the #pragma once i reserve the right to be wrong but am prety sure about it.

Am sure a UE 4 Dev drops by soon enofe and confirm this or not 😉
