Page 1 of 1

Loading quests from quest database during runtime

Posted: Mon Mar 14, 2022 9:29 am
by vikramapilla
Hi Tony,

I have a question regarding loading quests to the journal from the quest database.

I have two quest databases in my scene. Each database contains unique quests.

Depending on the situation in my scene, I would like to load either of the quests from these two databases into my journal.

I already tried the below code, but it doesn't seem to work. I could be wrong somewhere, could you please suggest on a way to resolve this issue?

Code: Select all

    public void LoadQuests(QuestDatabase database) {
        var journal = QuestMachine.GetQuestJournal();

        // clear any existing quests
        journal.questList.Clear();

        // add quests from the database
        foreach (var questAsset in questDatabase.questAssets) {
            journal.AddQuest(questAsset);
        }
    }

Re: Loading quests from quest database during runtime

Posted: Mon Mar 14, 2022 10:04 am
by Tony Li
Hi,

To clear the journal, please use journal.ResetToOriginalState() instead of journal.questList.Clear(). This will cleanly remove the quests from the journal.

Then use this code to add quest instances to the journal: (From How To: Start Quest From Script)

Code: Select all

journal.ResetToOriginalState();
foreach (var questAsset in questDatabase.questAssets) {
    GiveQuestToJournal(questAsset);
}
QuestMachineMessages.RefreshUIs(questInstance);

public void GiveQuestToJournal(Quest questAsset) {
    // Make a copy of the quest for the quester:
    var questInstance = questAsset.Clone();

    // Add the copy to the quester and activate it:
    var questerTextInfo = new QuestParticipantTextInfo(questJournal.id, questJournal.displayName, questJournal.image, null);
    questInstance.AssignQuester(questerTextInfo);
    questInstance.timesAccepted = 1;
    questJournal.AddQuest(questInstance);
    questInstance.SetState(QuestState.Active);
}

Re: Loading quests from quest database during runtime

Posted: Mon Mar 14, 2022 11:42 am
by vikramapilla
Hi Tony,

thanks for your quick response.

I tried your solution, it seems to work well to clear the journal and load during only the first attempt. Whenever I try to load assets from the database a second time, the journal fails to register any new incoming quests.

Re: Loading quests from quest database during runtime

Posted: Mon Mar 14, 2022 1:14 pm
by Tony Li
I don't know how to reproduce that. Can you send a reproduction project to tony (at) pixelcrushers.com?

Re: Loading quests from quest database during runtime

Posted: Tue Apr 05, 2022 12:24 pm
by Tony Li
Hi,

Thank you for sending the reproduction project. I replied to your email.

Re: Loading quests from quest database during runtime

Posted: Wed Apr 06, 2022 5:11 am
by vikramapilla
Tony Li wrote: Tue Apr 05, 2022 12:24 pm Hi,

Thank you for sending the reproduction project. I replied to your email.
Hi Tony,

thank you very much for sending me a patch to fix the issue. The response turnaround was really quick and I highly appreciate your support.

I can confirm that the runtime database change now happens without any problems. :)

Re: Loading quests from quest database during runtime

Posted: Wed Apr 06, 2022 9:20 am
by Tony Li
Great! Thanks for confirming.