TMap<enum, TArray<struct>> - error C2036: const struct * : unknown size - work around?

Code:

TMap<EPlayerControllerId, TArray<struct FPawnUniformColors>> TeamColors;

Error in compilation: error C2036: ‘const FPawnUniformColors *’ : unknown size

EPlayerControllerId is an enum.
FPawnUniformColors is a struct forward declared here, but in the cpp file the include to the source exists.

Looking for a workaround here. When I try to apply it to blueprint I get “nested container types are not supported”.

I use this setup with class pointers just fine, so my fast work around is to make FPawnUniformColors a UObject instead and make it a class type, but that annoys me that I have to do that.

Can someone shed some light on what is going on here?

EDIT: for lolz I put the #include statement in the .h file that existed in the cpp file. So now the #include statement where this struct resides is in both. That fixed the problem.

That doesn’t make much sense to me though. If its in the .cpp file, I don’t see why it can’t find the array size… but if I put the include in the .h file suddenly it works. Up to this point I have always put my includes largely in the cpp files. I suppose my root problem here is a C++ failure to understand when to put includes in .h vs .cpp.

You cannot forward declare a struct when the compiler needs to know its size, which is what happens when you want to declare a TArray, since the array needs to know the size of its elements
You can forward declare a struct when you only use a pointer to it

Having a TArray of a forward declared class pointer works because the size of the pointer is known, and the array only cares about the size of each of its elements

1 Like

Thank you. I solved my issue by removing the struct and turning it into a class.