Automatically Select First Quest in Quest Log Window

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Automatically Select First Quest in Quest Log Window

Post by Mackerel_Sky »

Hi,

I'm working on integrating the standard Quest Log UI into my project, and I'm having a bit of an issue regarding my control scheme- My game works on a keyboard only, and I want to automatically select the first quest in the main quest window. To do this I added a new script to to the Quest Titles Content game object here:

Image

My script is:

Code: Select all

    Button button;
    public int startIndexNumber; // number to start list check from
    // Start is called before the first frame update

    private void OnEnable()
    {
        print(transform.GetChild(startIndexNumber));
        if (transform.GetChild(startIndexNumber) != null)
        {
            button = transform.GetChild(startIndexNumber).GetComponent<Button>();
            button.Select();
        }
        else
        {
            print("no button in the index number");
        }
    }
Since the new quests are instantiated underneath Completed Quest Heading Template, I set startIndexNumber to 3 (4th child). However, on doing this I get an index out of range error on launching the game (expected, since there would not be a quest on game start yet), on first opening the log window (regardless of there being a quest in there or not), and then finally I get a print on 2nd opening onwards, but the button does not select, nor do I get the no button print.

Do you know why this is the case?

Sorry if this is not a Dialogue System question- I think it might be more of a general Unity thing.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Automatically Select First Quest in Quest Log Window

Post by Tony Li »

Hi,

Normally you'd want to make sure startIndexNumber is less than transform.childCount.

However, this seems like a useful option, so I've added it to the quest log window itself. Here's a patch:

DS_QuestLogWindowPatch_2020-04-12.unitypackage

The Selection Panel section has a new checkbox named "Select First Quest On Open".
Mackerel_Sky
Posts: 111
Joined: Mon Apr 08, 2019 8:01 am

Re: Automatically Select First Quest in Quest Log Window

Post by Mackerel_Sky »

Hey Tony,

The package works perfectly- thanks for the help!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Automatically Select First Quest in Quest Log Window

Post by Tony Li »

Glad to help!
Post Reply