How to set current selected/tracked node as 'True' programmatically

Announcements, support questions, and discussion for Quest Machine.
Post Reply
jlhacode
Posts: 77
Joined: Fri Jul 03, 2020 6:23 am

How to set current selected/tracked node as 'True' programmatically

Post by jlhacode »

Hi Tony,

I'm creating a quest debug menu, and I have a button marked "Complete current quest node", and I'm deciding on how I should implement it. The "current quest node" in this case is the selected quest in the quest journal.

My current idea is to:
1. Get a reference to the QuestJournalUI by calling QuestMachine.GetQuestJournal()
2. Getting the selectedQuest property
3. Getting the active node by iterating on the nodeList
4. Setting the state via SetState.

Would this be the most efficient way of getting the current selected node?
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to set current selected/tracked node as 'True' programmatically

Post by Tony Li »

Hi,

I assume you mean UnityUIQuestJournalUI.selectedQuest?

If so, you can get it like this:

Code: Select all

UnityUIQuestJournalUI questJournalUI = QuestMachine.GetQuestJournal().questJournalUI as UnityUIQuestJournalUI;
Quest selectedQuest = questJournalUI.selectedQuest;
In a quest, multiple nodes can be active at the same time. For example, in the demo's Coin Race quest, two nodes are active:
  • Node that counts the number of coins collected. (Leads to Success if the player collects enough coins.)
  • Node that runs the countdown timer. (Leads to Failure if countdown reaches zero.)
You could run through all nodes and identify which ones' GetState() == QuestNodeState.Active. Then you can set them to True. Note that if you set a node to True, it's possible that its Actions might also set other nodes to some other state.

Code: Select all

var activeNodes = selectedQuest.nodeList.FindAll(node => node.GetState() == QuestNodeState.Active);
foreach (QuestNode activeNode in activeNodes)
{
    activeNode.SetState(QuestNodeState.True);
}
Post Reply