Quest Journal breaking between scenes

Announcements, support questions, and discussion for Quest Machine.
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Journal breaking between scenes

Post by Tony Li »

You can put that code in a new script that's on a GameObject in the Quest Machine GameObject's hierarchy (such as the Quest Machine GameObject itself) or any GameObject that, like Quest Machine, is DontDestroyOnLoad.
mac
Posts: 81
Joined: Sat Aug 22, 2020 7:54 pm

Re: Quest Journal breaking between scenes

Post by mac »

Done that heres the script:

Code: Select all

using UnityEngine;
using PixelCrushers.QuestMachine;
using PixelCrushers;

public class CloseJournalUI : MonoBehaviour
{
    private void Start()
    {
        var journalUI = QuestMachine.defaultQuestJournalUI as UnityUIQuestJournalUI;
        var uiPanel = journalUI.GetComponent<UIPanel>();
        var uiManager = FindObjectOfType<UIManager>();
        uiPanel.onOpen.AddListener(uiManager.ToggleJournal);
        uiPanel.onClose.AddListener(uiManager.ToggleJournal);
    }
}
I supposed this would be executed with the attached image On Click() event, but nothing seems to happen. No errors in the console. (I started off with Awake instead of Start but that gave me a nullref for var uiPanel). Is this how it should be executed?
Attachments
Screenshot_1.png
Screenshot_1.png (5.26 KiB) Viewed 1328 times
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Journal breaking between scenes

Post by Tony Li »

The best way to open and close the journal UI is through the Quest Journal component. The Quest Journal component is usually on your player GameObject. Call QuestJournal.ShowJournal, HideJournal, or ToggleJournal.

It's also fine to call the UnityUIQuestJournalUI component's Hide method directly.

Both ways will implicitly call the journal UI's UIPanel.Close. You don't need to call it directly.
mac
Posts: 81
Joined: Sat Aug 22, 2020 7:54 pm

Re: Quest Journal breaking between scenes

Post by mac »

Awesome, everything's clear and working :)
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Journal breaking between scenes

Post by Tony Li »

Great!
biljiczop
Posts: 1
Joined: Fri Jan 07, 2022 6:50 am

Re: Quest Journal breaking between scenes

Post by biljiczop »

I have some things I would like to add to the function, such as unhiding the cursor, stop character from moving while the menu is open and so on.
User avatar
Tony Li
Posts: 21928
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest Journal breaking between scenes

Post by Tony Li »

Hi,

When Quest Machine's journal UI opens, it sends the message "Pause Player" to Quest Machine's Message System. When the UIs close, they send "Unpause Player".

You can add a script that listens for these messages. Example:
Spoiler
public class PausePlayerWhenMenuIsOpen : MonoBehaviour, IMessageHandler
{
void OnEnable()
{
MessageSystem.AddListener(this, "Pause Player", string.Empty);
MessageSystem.AddListener(this, "Unpause Player", string.Empty);
}

void OnDisable()
{
MessageSystem.RemoveListener(this, "Pause Player", string.Empty);
MessageSystem.RemoveListener(this, "Unpause Player", string.Empty);
}

public void OnMessage(MessageArgs messageArgs)
{
switch (messageArgs.message)
{
case "Pause Player":
// Unhide cursor, stop character from moving, etc.
break;
case "Unpause Player":
// Hide cursor, etc.
break;
}
}
}[/code]
Or use a Message Events component:

messageEvents.png
messageEvents.png (53.36 KiB) Viewed 1110 times

If you want to do the same for when the dialogue UI opens or some other UI opens, you can configure the UI to send the same messages.
Post Reply