Good day, community!
I’m working on creating quest system, everything works great, but I missed a point about Instanced UPROPERTY. Hope someone can give me an advice.
I have FMyQuest struct:
USTRUCT(BlueprintType)
struct FMyQuest
{
GENERATED_BODY()
public:
UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = "Quest system")
int32 Id;
UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = "Quest system")
FString Name;
UPROPERTY(EditInstanceOnly, BlueprintReadOnly, Category = "Quest system")
bool bIsCompleted;
int32 CurrentTask;
UPROPERTY(Instanced, EditInstanceOnly, BlueprintReadWrite, Category = "Quest system")
TArray<class UMyQuestTask*> Tasks;
};
and UMyQuestTask class, parent class for different types of task (go to point, kill monster, etc):
UCLASS(Blueprintable, BlueprintType, EditInlineNew, abstract)
class MAVRINDIALOGUE_API UMyQuestTask : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "Quest system")
FString Name;
UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "Quest system")
bool bIsCompleted;
virtual bool UpdateTask(UObject* _TriggeredObject, const FString& _Message);
};
After that I’m creating Data Asset to store all of my quests:
UCLASS(BlueprintType)
class MAVRINDIALOGUE_API UMyQuestDataAsset : public UDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category = "Quest system")
TArray<FMyQuest> Quests;
}
Player have an array of current quests. When player talk to someone, in that array I’m adding quest simple by Quests.Add(_Quest).
Let’s for example make an quest with one task - go to point. I’m taking quest from NPC, going to point and UGoToQuestTask (which is inherits from UMyQuestTask), bIsCompleted of task sets “true”.
BUT, here is a problem: in Data Assets that Task’s bIsCompleted become “true” too! Why so? I thought when I’m adding to an array, it creates a copy of that quests, but in real life they are shares values of Tasks.
I also noticed that when Quest’s (not Task) bIsCompleted in array of character becomes “true”, Quest’s bIsCompleted in Data Assets not becomes true. What point I’m missed?