I have a list of structs set up like this:
USTRUCT()
struct FBaseStruct{
GENERATED_USTRUCT_BODY()
float baseFloat;
int32 baseInt;
EStructType myType;
};
USTRUCT()
struct FSubtructA : public FBaseStruct {
GENERATED_USTRUCT_BODY()
TMap<int32, FString> differentUniqueValues;
};
USTRUCT()
struct FSubtructB : public FBaseStruct {
GENERATED_USTRUCT_BODY()
TArray<FString> uniqueValues;
};
I have a giant TArray that I want to divide up by subclass, which is easy enough:
TArray<FBaseStruct> baseArray;
for (int i = 0; i < baseArray.Nunm(); i++){
switch (EStructType){
case EStructType::StructA:
//do stuff with tmaps
break;
case EStructType::StructB:
//do stuff with strings
break;
default:
break;
}
}
Here’s where I’m stuck; how do I verify which subclass of EBaseStruct each array entry is? If the enum somehow gets set wrong, and I pass my system a SubstructA that thinks it’s a SubstructB, I’m going to end up referencing a bunch of values that don’t exist, confusing myself at best and crashing at worst.
So is there some kind of safety/sanity feature I can add, which verifies my substruct’s class before referencing it?