# How to use C++ ENUM with the UUserDefinedEnum Class

**URL:** <https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 27, 2020, 11:32pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101 "2020-11-27T23:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xlear](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xlear](https://forums.unrealengine.com/u/Xlear)\
**Post date:** [November 27, 2020, 11:32pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101/1 "2020-11-27T23:32:25Z")

</div>

Hello,

i have questions about the given UUserDefinedEnum Class.

1. How to use UUserDefinedEnum on the right way / should this class be used for ENUMs?
2. How can i create an ENUM with the given structures from the UUserDefinedEnum Class with the name of eg. ETestTypes?
3. What is the purpose for a .cpp file? (In my knowledge, a cpp file is not needed for ENUMs)

I hope someone knows about the “UUserDefinedEnum Class”

Thanks for your help -

**ETestTypes.h:**

```
#pragma once

#include "CoreMinimal.h"
#include "Engine/UserDefinedEnum.h"
#include "ETestTypes.generated.h"

/**
 *
 */
UCLASS()
class PROJECTA_API UETestTypes : public UUserDefinedEnum
{
	GENERATED_BODY()
	
};

```

**ETestTypes.cpp:**

```
// Fill out your copyright notice in the Description page of Project Settings.

#include "ETestTypes.h"
```

---

<div class="post-metadata">

**Author:** ![Lardo\_Deepdelver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lardo\_Deepdelver](https://forums.unrealengine.com/u/Lardo_Deepdelver)\
**Post date:** [December 4, 2020, 7:13pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101/2 "2020-12-04T19:13:26Z")

</div>

super confused why you would like to inherit from UUserDefinedEnum,  
if you just want to create a custom enum just do:

```
#pragma once

#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "YourEnum.generated.h"

UENUM(BlueprintType)
enum class EYourEnum : uint8
{
	Something,
    SomethingOther,
    SomethingElse
};
```

---

<div class="post-metadata">

**Author:** ![Xlear](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xlear](https://forums.unrealengine.com/u/Xlear)\
**Post date:** [December 4, 2020, 10:43pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101/3 "2020-12-04T22:43:20Z")

</div>

thanks for your answer. in general you are right, but because epic itself describes this class that way (and the first point is very interesting)

1. EnumType is always UEnum::ECppForm::Namespaced (to comfortable handle names collisions)
2. always have the last ‘\_MAX’ enumerator, that cannot be changed by user
3. Full enumerator name has form: ‘=""\>::’ An Enumeration is a list of named values.

> **[UUserDefinedEnum](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Engine/UUserDefinedEnum/)**
>
> User defined enumerations:

---

<div class="post-metadata">

**Author:** ![Lardo\_Deepdelver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lardo\_Deepdelver](https://forums.unrealengine.com/u/Lardo_Deepdelver)\
**Post date:** [December 4, 2020, 11:15pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101/4 "2020-12-04T23:15:31Z")

</div>

Sure but name collisions are only a problem for enums, not enum classes, enum classes are strongly typed.

the \_MAx for enumerations you can add yourself

```
UENUM(BlueprintType)
 enum class EYourEnum : uint8
 {
     Something,
     SomethingOther,
     SomethingElse,
     YourEnum_Max UMETA(Hidden),
 };

```

the names are a little harder, but in most cases, you don’t need names, if you just want to use the enum as a state value.

I think the only purpose of UUserDefinedEnum is to be able to create enums in the editor, which if you are using C++ anyway is not really necessary for you. In general, if you are using C++ it’s a good practice to define all your types in C++, enum classes, structs. This allows you to use them in C++ and in blueprints.

---

<div class="post-metadata">

**Author:** ![Xlear](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xlear](https://forums.unrealengine.com/u/Xlear)\
**Post date:** [December 4, 2020, 11:18pm UTC](https://forums.unrealengine.com/t/how-to-use-c-enum-with-the-uuserdefinedenum-class/475101/5 "2020-12-04T23:18:41Z")

</div>

ok, thanks for the detailed explanation 🙂
