Hello! I'd like to create a Journal button that works regardless of what scene you're in, but I'm not sure how to do that.
Here's my setup right now:
The problem is, when I go to a new scene in play mode, the onclick events of my journal button say "Missing."
I think that's because the Dialogue UI is donotdestroy, but my journal button isn't, so in the next scene, the prefab is referring to something that's not there like it used to be.
What's the "right" way to fix this? I'm thinking the easiest might be to take the Quest Log out of the Dialogue UI and move it to a non-donotdestroy part of the hierarchy.
A journal button that works on every scene
Re: A journal button that works on every scene
You can add a script like this to your UI Button and configure OnClick() to call its OpenQuestLogWindow() method:
You can also find similar code in QuestLogWindowHotkey.cs, which binds a key to toggle the quest log window open and closed.
Code: Select all
using UnityEngine;
public class QuestLogWindowOpener : MonoBehaviour
{
public void OpenQuestLogWindow()
{
FindObjectOfType<PixelCrushers.DialogueSystem.QuestLogWindow>().Open();
}
}
Re: A journal button that works on every scene
Ah. Is that performant? I never know with those Find methods.
In the end I decided to put my journal button inside the Dialogue Manager so it can always have a reference to the Quest Log field.
In the end I decided to put my journal button inside the Dialogue Manager so it can always have a reference to the Quest Log field.
Re: A journal button that works on every scene
It's absolutely fine for a single use. You wouldn't want to use FindObjectOfType inside a loop that repeats every frame, such as an Update() method.
Even so, the QuestLogWindowHotkey script I mentioned above caches the FindObjectOfType result so it only needs to look it up once after changing to a new scene.
Even so, the QuestLogWindowHotkey script I mentioned above caches the FindObjectOfType result so it only needs to look it up once after changing to a new scene.