I’m implementing a variation of the command pattern where I want to encapsulate every possible AI command (“Receive an item, attack another NPC, change locations,” etc) in a class, and store sequences of these commands in an array to be executed in order. I originally tried to do this with structs, the idea being that each child would have its own unique variables (storing which item they receive, which character they would attack, or anything else), and an override of a common Execute function that would actually call the desired manager/logic objects and enact the action like this:
USTRUCT(BlueprintType)
struct FTestBase {
GENERATED_BODY()
virtual void Execute() {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Base function");
}
};
USTRUCT(BlueprintType)
struct FTestChild : public FTestBase {
GENERATED_BODY()
void Execute() override {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "Child function");
}
};
However, I learned that you can’t override structs like this; if you have an array of type FTestBase, even if you fill it with variations of FTestChild the compiler will treat them like instances of FTestBase. The obvious solution to this seems to be doing the exact same logic with classes, instead of structs, but I’m really unclear on what class would actually be appropriate for data storage; the two simplest things I can think of would be to derive from AInfo or even just UObject, but there’s an awful lot of functionality there that I don’t need. Is there an obvious class I should be using for this?