Loading quests from quest database during runtime

Announcements, support questions, and discussion for Quest Machine.
Post Reply
vikramapilla
Posts: 4
Joined: Mon Mar 14, 2022 9:22 am

Loading quests from quest database during runtime

Post 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);
        }
    }
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading quests from quest database during runtime

Post 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);
}
vikramapilla
Posts: 4
Joined: Mon Mar 14, 2022 9:22 am

Re: Loading quests from quest database during runtime

Post 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.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading quests from quest database during runtime

Post by Tony Li »

I don't know how to reproduce that. Can you send a reproduction project to tony (at) pixelcrushers.com?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading quests from quest database during runtime

Post by Tony Li »

Hi,

Thank you for sending the reproduction project. I replied to your email.
vikramapilla
Posts: 4
Joined: Mon Mar 14, 2022 9:22 am

Re: Loading quests from quest database during runtime

Post 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. :)
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading quests from quest database during runtime

Post by Tony Li »

Great! Thanks for confirming.
Post Reply