I have a base struct FMyStructBase, and a bunch of child structs FMyStructChild : public FMyStructBase. I’m iterating through a TArray, identifying which subchild each member is, and then handling each child differently.
Where I’m running into trouble is accessing data unique to the child class. As an example, say I have the following practice version:
USTRUCT(BlueprintType)
struct FMyChildStruct : public FMyBaseStruct {
GENERATED_BODY()
UPROPERTY()
float uniqueFloat;
};
USTRUCT(BlueprintType)
struct FMyBaseStruct {
GENERATED_BODY()
};
In order to access the float, I take a member I know for a fact to belong to the correct child class, and try to cast it:
FMyBaseStruct baseVersion;
FMyChildStruct childVersion;
baseVersion = childVersion;
FMyChildStruct tempChild = Cast<FMyChildStruct>(childVersion); //Cast the object to the desired subclass
if (childVersion) { //If the cast succeeded...
return childVersion.uniqueFloat; //Access its unique members and do whatever
}
However, it really doesn’t like my cast; this returns an error at compile-time, “None of the 2 overloads could convert all the argument types”. Is it not possible to cast structs at all?