# New Enum Impenemtation with TMap

**URL:** <https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517>\
**Category:** C++\
**Tags:** error, ENUM, tmap, unreal-engine, question, CPP\
**Created:** [October 7, 2015, 10:52am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517 "2015-10-07T10:52:11Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 10:52am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/1 "2015-10-07T10:52:11Z")

</div>

Hey guys so I am having a compilation issue with UE involving an ENUM as a TMap keyvalue.  
Here is my Enum

```
UENUM(BlueprintType)
enum class EStat : uint8
{
	ATTACK UMETA(DisplayName = "Attack"),
	DEFENSE UMETA(DisplayName = "Defense"),
	HEALTH UMETA(DisplayName = "Health"),
	DODGE UMETA(DisplayName = "Dodge"),
	AGILITY UMETA(DisplayName = "Agility")
};

```

and the Tmap using it is

```
TMap<EStat, int32> StatReward;

```

I am seeing 2 errors

C2065: ‘EStat’ : undeclared identifier

error C2923: ‘TMap’ : ‘EStat’ is not a valid template type argument for parameter

any ideas?

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 11:03am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/2 "2015-10-07T11:03:53Z")

</div>

Where is EState declared?

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 11:08am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/3 "2015-10-07T11:08:53Z")

</div>

Within a header file called CharBase.h but I am including it into a different header file with

```
#include "CharBase.h"

```

The class intellisense is shown so I know it is finding it correctly.

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 11:35am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/4 "2015-10-07T11:35:14Z")

</div>

Never trust intellisense with extremely large codes 😛  
try including CharBase.h in the file where the TMap is declared.

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 12:30pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/5 "2015-10-07T12:30:03Z")

</div>

I did, I put

```
#include "CharBase.h"

```

at the top like I thought was needed, that’s why I am so confused

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 1:19pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/6 "2015-10-07T13:19:06Z")

</div>

By any chance that that header is in a sub directory beyond classes, public or private?

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 1:20pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/7 "2015-10-07T13:20:03Z")

</div>

By any chance that that header is in a sub directory beyond classes, public or private?

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 1:42pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/8 "2015-10-07T13:42:40Z")

</div>

Same directory I, not sure what you mean by public or private it is in the header exactly how it is shown not in a class under a public: declaration.

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 1:43pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/9 "2015-10-07T13:43:54Z")

</div>

By classes, private and public I mean the folders.

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 1:49pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/10 "2015-10-07T13:49:08Z")

</div>

Ok, the all are in the same folder

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 1:52pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/11 "2015-10-07T13:52:57Z")

</div>

Can you please post the code up to the TMap deceleration?

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 2:09pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/12 "2015-10-07T14:09:27Z")

</div>

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

```
#pragma once
#include "CharBase.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "QuestRewardExp.generated.h"

UENUM(BlueprintType) //"BlueprintType" is essential to include
enum class EExpType : uint8
{
	EXP UMETA(DisplayName = "Experience"),
	STAT UMETA(DisplayName = "Stat"),
	BOTH	UMETA(DisplayName = "Both")
};

/**
 * 
 */
UCLASS()
class TERRAIN_API UQuestRewardExp : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
	public:

		UPROPERTY(EditAnywhere, BlueprintReadWrite)
		EExpType RewardType;

		TMap<EStat, int32> StatReward;

		UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 ExperienceRewardAmount;
	
	
};
```

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 2:20pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/13 "2015-10-07T14:20:28Z")

</div>

I just compiled an example close to yours and all is good… can you post the full paths to QuestRewardExp.h and CharBase.h?

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 2:27pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/14 "2015-10-07T14:27:51Z")

</div>

![61708-directory.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/0/2206fc2dc4824ae90711c6789bee9f02ead6e9b2.png)

---

<div class="post-metadata">

**Author:** ![lion032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lion032](https://forums.unrealengine.com/u/lion032)\
**Post date:** [October 7, 2015, 2:36pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/15 "2015-10-07T14:36:37Z")

</div>

I am unable to reproduce the problem, can you post CharBase.h please?

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 2:47pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/16 "2015-10-07T14:47:08Z")

</div>

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

```
#pragma once

#include "GameFramework/Character.h"
#include "CharBase.generated.h"

UENUM(BlueprintType)
enum class EStat : uint8
{
	ATTACK UMETA(DisplayName = "Attack"),
	DEFENSE UMETA(DisplayName = "Defense"),
	HEALTH UMETA(DisplayName = "Health"),
	DODGE UMETA(DisplayName = "Dodge"),
	AGILITY UMETA(DisplayName = "Agility")
};

UCLASS()
class TERRAIN_API ACharBase : public ACharacter
{
	GENERATED_BODY()

public:

	
	// Sets default values for this character's properties
	ACharBase();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	
	
};
```

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 3:12pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/17 "2015-10-07T15:12:25Z")

</div>

Ok I found that I need to put the enum in a class and reference it through the class. Using the code below I can now use the Enum in the TMap key value by.

```
 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "GameFramework/Character.h"
 #include "CharBase.generated.h"
 
 UCLASS()
 class TERRAIN_API ACharBase : public ACharacter
 {
     GENERATED_BODY()
 
 public:

 UENUM(BlueprintType)
 enum class EStat : uint8
 {
     ATTACK UMETA(DisplayName = "Attack"),
     DEFENSE UMETA(DisplayName = "Defense"),
     HEALTH UMETA(DisplayName = "Health"),
     DODGE UMETA(DisplayName = "Dodge"),
     AGILITY UMETA(DisplayName = "Agility")
 };
     
     // Sets default values for this character's properties
     ACharBase();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
 
     
     
 };

```

And here is how I use it.

```
TMap<ACharBase::EStat, int32> StatReward;
```

---

<div class="post-metadata">

**Author:** ![Dtaggart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dtaggart](https://forums.unrealengine.com/u/Dtaggart)\
**Post date:** [October 7, 2015, 3:12pm UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/18 "2015-10-07T15:12:56Z")

</div>

Figured it out, see my answer post. Thanks so much!

---

<div class="post-metadata">

**Author:** ![ianFisch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ianFisch](https://forums.unrealengine.com/u/ianFisch)\
**Post date:** [May 25, 2021, 2:45am UTC](https://forums.unrealengine.com/t/new-enum-impenemtation-with-tmap/334517/19 "2021-05-25T02:45:45Z")

</div>

Unreal no longer lets you define an Enum inside of a class like this. This answer should probably be deleted or something.
