# How to create a map using enumerator keys in C++

**URL:** <https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, question, CPP\
**Created:** [April 3, 2022, 4:46am UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060 "2022-04-03T04:46:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RCE\_WillPimentel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rce_willpimentel/32/960936_2.png) [@RCE\_WillPimentel](https://forums.unrealengine.com/u/RCE_WillPimentel)\
**Post date:** [April 3, 2022, 4:46am UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060/1 "2022-04-03T04:46:06Z")

</div>

Hey, I’m looking to migrate a bunch of variables to C++ instead of continuing to use Blueprints. I’m writing a framework plugin for Unreal Engine that I intend for my team to use for all upcoming projects, and since one of those includes a very large-scale open world title, having thousands of instances of Blueprints potentially running heavy code may not work out, so I’d like to write this all into C++ and be futureproofed now rather than later.

I’m trying to convert this:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/b/a7bfd9da87db56eacc846cff6c64f18805d03a87.png)  
…into C++.

The first is an array of ECollisionChannel enums, not sure how I’d put the syntax together for that one.  
The next two are mappings of physical surfaces to sound bases, which I’m _really_ struggling with. I’ve given it a couple of shots and as of now have basically just been hunting through the API and brute forcing different syntax in hopes of getting it to work, but so far, I’ve got nothing, so I’m coming to the forums to see if anyone might have an answer.

Thanks and have a good rest of your day, morning, afternoon, night, etc.

---

<div class="post-metadata">

**Author:** ![BrunoCaxito](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brunocaxito/32/706161_2.png) [@BrunoCaxito](https://forums.unrealengine.com/u/BrunoCaxito)\
**Post date:** [April 3, 2022, 9:37pm UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060/2 "2022-04-03T21:37:51Z")

</div>

_ **TArray** _ for arrays, _ **TMap\<T1, T2\>** _ for maps, where T is the entry type.

```auto
TArray<ECollisionChannel> MyVar1;
TMap<EPhysicalSurface, USoundBase*> MyVar2;
TMap<EPhysicalSurface, USoundBase*> MyVar3;

```

Notice that UObjects must be pointers.

---

<div class="post-metadata">

**Author:** ![RCE\_WillPimentel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rce_willpimentel/32/960936_2.png) [@RCE\_WillPimentel](https://forums.unrealengine.com/u/RCE_WillPimentel)\
**Post date:** [April 20, 2022, 3:32pm UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060/3 "2022-04-20T15:32:54Z")

</div>

Thanks, very helpful! Most of the errors I was previously having have gone away.  
However, I still get an error trying to use this.

Error: You canot use the raw enum name as a type for member variables, instead use TEnumAsByte or a C++11 enum class with an explicit underlying type.

I’m not exactly a professional at C++, so I’m not 100% sure what this means… I think I understand what it means by asking me to use an enumerator as a byte but I can’t be 100% sure.

Thanks for the help, it’s greatly appreciated.

---

<div class="post-metadata">

**Author:** ![BrunoCaxito](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/brunocaxito/32/706161_2.png) [@BrunoCaxito](https://forums.unrealengine.com/u/BrunoCaxito)\
**Post date:** [April 24, 2022, 2:39am UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060/4 "2022-04-24T02:39:56Z")

</div>

Hello,

I think your problem is the same as this thread. Hope it helps!

[How to properly insert Engine-Default Enums in FStructs - Pipeline & Plugins / Editor Scripting - Unreal Engine Forums](https://forums.unrealengine.com/t/how-to-properly-insert-engine-default-enums-in-fstructs/436545)

---

<div class="post-metadata">

**Author:** ![RCE\_WillPimentel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rce_willpimentel/32/960936_2.png) [@RCE\_WillPimentel](https://forums.unrealengine.com/u/RCE_WillPimentel)\
**Post date:** [April 24, 2022, 2:09pm UTC](https://forums.unrealengine.com/t/how-to-create-a-map-using-enumerator-keys-in-c/512060/5 "2022-04-24T14:09:16Z")

</div>

Good deal, I’ll test this when I get home!
