QuestStateSerializer changes state to WaitingToStart

Announcements, support questions, and discussion for Quest Machine.
Post Reply
LaurenVR
Posts: 1
Joined: Tue Sep 08, 2020 5:53 pm

QuestStateSerializer changes state to WaitingToStart

Post by LaurenVR »

I'm running into an issue with the QuestStateSerializer. Basically, when the player makes progress in the quest, I save it to a JSON string and use it to do a couple other things. The problem is that quests that are in the Active state become WaitingToStart when they get saved! I've tracked it down through the following code path:

- I call QuestListContainer.RecordData
- QuestListContainer.RecordData calls QuestStateSerializer.Serialize (line 338)
- That calls QuestStateSerializer.WriteQuestDataToStream (line 39)
- That calls Quest.UpdateCooldown (line 80)
- Finally this calls into BecomeOfferable, which sets it to be WaitingToStart (see snippet below)

TL;DR: If I save the quest while the user is in progress, they can't finish it, because it's changed from Active to WaitingToStart, instead of just saving it as Active.
Spoiler

Code: Select all

        public void BecomeOfferable()
        {
            try
            {
                if (GetState() != QuestState.WaitingToStart) SetState(QuestState.WaitingToStart);
                questOfferable(this);
                SetQuestIndicatorState(questGiverID, QuestIndicatorState.Offer);
            }
            catch (Exception e) // Don't let exceptions in user-added events break our code.
            {
                if (Debug.isDebugBuild) Debug.LogException(e);
            }
        }
        
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: QuestStateSerializer changes state to WaitingToStart

Post by Tony Li »

Hi,

I'm assuming the player has a QuestJournal component and the quest giver NPC has a QuestGiver component.

When the player accepts a quest from the NPC, the player's QuestJournal receives a copy of the NPC's quest.

The instance in the player's QuestJournal is set to the Active state.

If the quest is repeatable, the instance in the NPC's QuestGiver list eventually returns to the WaitingToStart state after the cooldown duration.

Make sure you're serializing the instance of the quest that's in the player's QuestJournal.
Post Reply