The code is fairly simple, but I'd like to extend it to account for Quest Nodes which may have their own individual waypoints. It checks if you toggle on/off a quest and checks through a list of GameObjects I have set up and sets them active or not (I'm sure there is a better way to do this, as I don't like having to name things similarly for it to work, but it's a start).
Code: Select all
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers;
using PixelCrushers.QuestMachine;
public class Waypoints : SingletonMonobehaviour<Waypoints>, IMessageHandler
{
public List<GameObject> waypoints = new List<GameObject>();
private string waypointString;
private string active;
void OnEnable()
{
MessageSystem.AddListener(this, QuestMachineMessages.QuestTrackToggleChangedMessage, "");
}
void IMessageHandler.OnMessage(MessageArgs args)
{
SetQuestWaypoints(args);
}
public void SetQuestWaypoints(MessageArgs args)
{
//PixelCrushers.QuestMachine.Quest quest = QuestMachine.GetQuestInstance(args.parameter);
//Debug.Log(quest);
waypointString = "Waypoint - " + args.parameter.ToString();
active = args.firstValue.ToString();
foreach (var waypoint in waypoints)
{
if (waypoint.name == waypointString && active == "True")
{
waypoint.SetActive(true);
Debug.Log("Turning " + waypoint.name + "waypoint on, because it's " + active);
}
else if (waypoint.name == waypointString && active == "False")
{
waypoint.SetActive(false);
Debug.Log("Turning " + waypoint.name + "waypoint off, because it's " + active);
}
}
}
void OnDisable()
{
MessageSystem.RemoveListener(this, QuestMachineMessages.QuestTrackToggleChangedMessage, "");
}
}
- The line in the code that is commented out: PixelCrushers.QuestMachine.Quest quest = QuestMachine.GetQuestInstance(args.parameter); does work. And I'll be using that to grab quest nodes and states in order to turn on/off waypoint markers. However, when the game loads, even though I'm getting the quest correctly in args.parameter, the quest instance is returning null. If a message comes through after the game has loaded it works fine. Is the Quest Journal not fully loaded at this point?
- I have two quests in the Quest Database at the moment. If I accept one quest and not another, when I load a new scene (or the game), it will actually send a message for both quests (since my code is looking for all quests) and the quest that has not been accepted at all will return "True" from QuestTrackToggleChangedMessage. This only happens on scene change and on game load, but not when toggling anything in the Quest Journal. I'm assuming something is just wrong with my code. I'm definitely utilizing the fact that something (I assumed the Quest Journal, but maybe not) is sending a message on load or scene change, but I'm not sure why it's returning "True" for a quest that I have never even accepted and isn't in my player Quest Journal.
- When a current node in a quest becomes true, I have it manually deactivate the waypoint game object that's associated with it in the Actions in the Quest Machine editor. This works great, but I assume it doesn't run these actions when the game is loaded, right?
- I'm running into another issue, and I wonder if it's related. One of my quest nodes has a condition that looks to see if other nodes are true, and when I load the game, I get some warnings that the Quest Machine can't find a quest with the ID of the quest. (see screenshot) https://ibb.co/k4V861V The quest conditions works perfectly fine whenever I complete them in game, and this warning only shows up on game load.
- Is there a better way to be doing all of this that I'm not thinking of?