USTRUCT and inheritance

This is by design, but you can get around it in special cases. Typically - Reflection requires that the primary type your inherit from must also be a reflected type. You can use multiple inheritance, but the additional types that you inherit from cannot be reflected types.

However there are cases where it’s legitimate to declare a new reflected type but also inherit from a non-reflected type - particularly for USTRUCT(). For obvious reasons you can’t expose this to the reflection system, but using the #if CPP pre-processor macro you can tell UHT to skip certain lines which will allow these cases to compile. This is how I am able to use an interface class for these two structs:



class IST_ComboBoxItem
{
public:
    virtual ~IST_ComboBoxItem() {}

    virtual FText GetDisplayText() const = 0;
};

USTRUCT(BlueprintType)
struct FOption_StringValue
#if CPP
    : public IST_ComboBoxItem
#endif
{};

USTRUCT(BlueprintType)
struct FOption_DiscreteValue
#if CPP
    : public IST_ComboBoxItem
#endif
{}


18 Likes