Per Rama’s excellent advice in UDataAsset vs Blueprintable UObject - C++ Gameplay Programming - Unreal Engine Forums , I’m creating a data holder for my quest system by extending UDataAsset:
UCLASS(BlueprintType)
class UQuestObjective : public UDataAsset {
GENERATED_BODY()
public:
UFUNCTION()
virtual bool IsComplete() {
return true;
}
};
UCLASS(BlueprintType)
class UQuestKillObjective : public UQuestObjective {
GENERATED_BODY()
public:
UPROPERTY()
int32 enemiesKilled;
UPROPERTY()
int32 killsRequired;
UFUNCTION()
bool IsComplete() override{
if (enemiesKilled >= killsRequired) {
return true;
}
else {
return false;
}
}
};
As you can see, my logic explicitly relies on my ability to override IsComplete() and store a quest’s entire string of objectives as an array of UQuestObjective*, if it weren’t for that I would just do this with structs.
That having been said, how do I safely declare an instance of my class when I need to create a new object? If this were a struct I could just write “UQuestKillObjective newObjective”, and if it extended UActor I could use GetWorld()->SpawnActor, but I’ve never had the need to create and destroy UObjects that don’t inherit from U Actor before, so I have no idea what the safe procedure is.