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

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:
…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.

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

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

Notice that UObjects must be pointers.

1 Like

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.


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

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