# How to use Behavior Tree Enum cpp

**URL:** <https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353>\
**Category:** C++\
**Tags:** Behavior-Tree, ENUM, unreal-engine, CPP, UE4-27, question\
**Created:** [February 7, 2022, 4:28pm UTC](https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353 "2022-02-07T16:28:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akaPrometh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@akaPrometh](https://forums.unrealengine.com/u/akaPrometh)\
**Post date:** [February 7, 2022, 4:28pm UTC](https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353/1 "2022-02-07T16:28:56Z")

</div>

Hi,  
I cannot find any resource on how to implement cpp enums for Behavior Trees.  
I have UE generate me this, but no idea on how to fill it.  
Thanks \<3 !

```auto
/**
 * 
 */
UCLASS()
class TPSMPPG_API UBBKE_AIState : public UBlackboardKeyType_Enum
{
	GENERATED_BODY()
	
};

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_68681eee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_68681eee](https://forums.unrealengine.com/u/anonymous_user_68681eee)\
**Post date:** [February 7, 2022, 5:06pm UTC](https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353/2 "2022-02-07T17:06:53Z")

</div>

This is how I create enums in CPP  
Create new empty C++ class in unreal editor  
editor will create header and cpp files for you  
in .h file replace generated class by the content below:

```auto
UENUM(BlueprintType)
enum class EUBBKE_AIState : uint8  
{
	OptionOne, 
	OptionTwo
};

```

In cpp file remove generated constructor and destructor.  
After compile EUBBKE\_AIState enum should be visible in BT and in Blueprints too

---

<div class="post-metadata">

**Author:** ![akaPrometh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@akaPrometh](https://forums.unrealengine.com/u/akaPrometh)\
**Post date:** [February 9, 2022, 2:26pm UTC](https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353/3 "2022-02-09T14:26:07Z")

</div>

Thanks Phoebus89  
You gave the correct steps to create an enum in CPP.  
Turns out the UBlackboardKeyType\_Enum unreal4 proposed me is.. useless for this case.  
A ‘simple’ enum is enough.

**However these arent enough to use the enum as a Blackboard variable type.**  
It appears we have to manually input the enum’s name in the field ‘Enum Name’ and then unreal will autofill ‘Enum Type’  
For example see answerof [Mewbits](https://forums.unrealengine.com/u/Mewbits) in

> [@Why enum, declared in c++ does not accessible to choose if BlackBoard?](https://forums.unrealengine.com/t/why-enum-declared-in-c-does-not-accessible-to-choose-if-blackboard/45884/4):
>
> I’m having the exact same issue. I declared the Enum the same way (except without the =0 part) and restarted the engine after compiling the code. It’s located in a header file that is listed in my project header file so that it’s accessible anywhere in the project. I can create variables and reference it anywhere. Except I can’t set it as the Enum type in Blackboard. Did you ever find a way to fix this issue? I’m in UE 4.23 Edit: Found the solution:

Eh, more weird cpp exceptions ‘blackmagic’ 🙄

---

<div class="post-metadata">

**Author:** ![AlexeyL2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlexeyL2](https://forums.unrealengine.com/u/AlexeyL2)\
**Post date:** [February 5, 2024, 11:35am UTC](https://forums.unrealengine.com/t/how-to-use-behavior-tree-enum-cpp/495353/4 "2024-02-05T11:35:50Z")

</div>

@akaPrometh, thanks a lot! I was also wandering how to add C++ enum to Behavior Tree. Current way is really not obvious!
