Change Active Quest Selection With Script

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Rhaelix
Posts: 4
Joined: Wed Mar 25, 2020 8:39 am

Change Active Quest Selection With Script

Post by Rhaelix »

Hello,

We have implemented Quest Machine into our project and have been running with it for a while. However, we are adding new features that trigger events through script and not user input. I am attempting to figure out how to change the currently selected "Active Quest" in the opened Quest Journal through script, instead of mouse input. If I can nail down the function that is called to pass the item's array ID to the change function that displays newly selected Active Quest details on the right and changes the highlighted Active on the left, I should be able to handle the rest.

Thanks in advance!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Active Quest Selection With Script

Post by Tony Li »

Hi,

The UnityUIQuestJournalUI has a protected property selectedQuest:

Code: Select all

protected Quest selectedQuest { get; set; }
You can make a subclass of UnityUIQuestJournalUI and add a method to set selectedQuest and repaint the UI:

Code: Select all

public class MyQuestJournalUI : UnityUIQuestJournalUI
{
    public SelectQuest(Quest quest)
    {
        selectedQuest = quest;
        Repaint();
    }
    
    // Alternate version:
    public SelectQuest(int i)
    {
        if (questJournal != null && 0 <= i && i < questJournal.questList.Count)
        {
            selectedQuest = questJournal.questList[i];
            Repaint();
        }
    }
}
Rhaelix
Posts: 4
Joined: Wed Mar 25, 2020 8:39 am

Re: Change Active Quest Selection With Script

Post by Rhaelix »

This is more than I expected, Tony. You have the best product support and always go above and beyond.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Active Quest Selection With Script

Post by Tony Li »

Thanks! Glad to help!

Note: I typed the example above directly into my reply. It's missing niceties such as "using" statements at the top, and it may have typos.
Post Reply