Page 2 of 2

Re: Quest Journal breaking between scenes

Posted: Wed May 26, 2021 7:14 pm
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.

Re: Quest Journal breaking between scenes

Posted: Wed May 26, 2021 9:36 pm
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?

Re: Quest Journal breaking between scenes

Posted: Wed May 26, 2021 9:45 pm
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.

Re: Quest Journal breaking between scenes

Posted: Thu May 27, 2021 12:37 am
by mac
Awesome, everything's clear and working :)

Re: Quest Journal breaking between scenes

Posted: Thu May 27, 2021 7:59 am
by Tony Li
Great!

Re: Quest Journal breaking between scenes

Posted: Fri Jan 07, 2022 7:17 am
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.

Re: Quest Journal breaking between scenes

Posted: Fri Jan 07, 2022 10:34 am
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 1113 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.