Hi there, I'm very new to unity and coding in general so sorry if this is a silly question, but how do I open the quest log window with a button click? I tried the call open () method in the button's on click but nothing shows up when I play the game. The hotkey (J) works fine though.
Clicking the button does seem to register as even though the quest log window doesn't show up, it has stopped my player character from moving(but not turning around). I feel the solution to this should be really simple but I'm just not getting it after trying for a whole night. Any help would be appreciated!
Open quest log window via button click
Open quest log window via button click
- Attachments
-
- buttonclick.JPG (13.97 KiB) Viewed 247 times
Re: Open quest log window via button click
Hi,
In your Button's OnClick() event, make sure to assign the instance of the quest log window that's in your scene or in the Dialogue Manager's Canvas, not the quest log window prefab. Since the prefab isn't in a scene, it isn't visible.
If your quest log window is added to the scene by the Dialogue Manager's Instantiate Prefabs component:
Then you'll need to either (1) remove it from Instantiate Prefabs and add an instance to the Dialogue Manager's Canvas:
or (2) use a small script like this on your Button: (no need to configure OnClick() in this case)
QuestLogWindowButton .cs
One other note: The Dialogue Manager GameObject is a "Don't Destroy On Load" GameObject. This means it survives scene changes. Don't make inspector connections between Don't Destroy On Load GameObjects such as the Dialogue Manager and non-Don't Destroy On Load GameObjects. Use the script above instead. A deeper explanation is in this post.
In your Button's OnClick() event, make sure to assign the instance of the quest log window that's in your scene or in the Dialogue Manager's Canvas, not the quest log window prefab. Since the prefab isn't in a scene, it isn't visible.
If your quest log window is added to the scene by the Dialogue Manager's Instantiate Prefabs component:
Then you'll need to either (1) remove it from Instantiate Prefabs and add an instance to the Dialogue Manager's Canvas:
or (2) use a small script like this on your Button: (no need to configure OnClick() in this case)
QuestLogWindowButton .cs
Code: Select all
using UnityEngine;
using UnityEngine.UI;
namespace PixelCrushers.DialogueSystem
{
[RequireComponent(typeof(Button))]
public class QuestLogWindowButton : MonoBehaviour
{
[Tooltip("(Optional) Use this quest log window. If unassigned, will automatically find quest log window in scene. If you assign a window, assign a scene instance, not an uninstantiated prefab.")]
public QuestLogWindow questLogWindow;
public QuestLogWindow runtimeQuestLogWindow
{
get
{
if (questLogWindow == null) questLogWindow = GameObjectUtility.FindFirstObjectByType<QuestLogWindow>();
return questLogWindow;
}
}
private void Awake()
{
if (questLogWindow == null) questLogWindow = GameObjectUtility.FindFirstObjectByType<QuestLogWindow>();
}
private void Start()
{
GetComponent<Button>().onClick.AddListener(() =>
{
if (runtimeQuestLogWindow != null)
{
if (runtimeQuestLogWindow.isOpen) runtimeQuestLogWindow.Close();
else runtimeQuestLogWindow.Open();
}
});
}
}
}
Re: Open quest log window via button click
Thank you! Both prefab instance and script worked great and I'll keep the side note about scene changes in mind moving forward.
Re: Open quest log window via button click
Glad to help!