Page 1 of 1

[HOWTO] How To: Auto-Open Quest Journal When Accepting Quest

Posted: Thu Jan 14, 2021 2:17 pm
by Tony Li
Add this script to the scene (e.g., Player) to auto-open the quest journal UI when a quest goes active.

AutoOpenJournalOnNewQuest.cs

Code: Select all

using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;

public class AutoOpenJournalOnNewQuest : MonoBehaviour, IMessageHandler
{
    private void OnEnable()
    {
        MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, string.Empty);
    }

    private void OnDisable()
    {
        MessageSystem.RemoveListener(this);
    }

    public void OnMessage(MessageArgs messageArgs)
    {
        string questID = messageArgs.parameter;
        bool isMainQuestState = (messageArgs.values[0] == null);
        if (isMainQuestState)
        {
            QuestState questState = (QuestState)messageArgs.values[1];
            if (questState == QuestState.Active)
            {
                var journal = QuestMachine.GetQuestJournal();
                journal.ShowJournalUI();
                var journalUI = journal.questJournalUI as UnityUIQuestJournalUI;
                if (journalUI != null) journalUI.SelectQuest(journal.FindQuest(questID));
            }
        }
    }
}
Edit: Updated to show quest that was just activated.

Re: [HOWTO] How To: Auto-Open Quest Journal When Accepting Quest

Posted: Thu Jan 14, 2021 2:35 pm
by CamperJohn
This works like a top...thanks for sharing. :D