Page 1 of 1

Automatically Select First Quest in Quest Log Window

Posted: Sun Apr 12, 2020 6:53 am
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.

Re: Automatically Select First Quest in Quest Log Window

Posted: Sun Apr 12, 2020 9:19 am
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".

Re: Automatically Select First Quest in Quest Log Window

Posted: Mon Apr 13, 2020 10:09 am
by Mackerel_Sky
Hey Tony,

The package works perfectly- thanks for the help!

Re: Automatically Select First Quest in Quest Log Window

Posted: Mon Apr 13, 2020 10:13 am
by Tony Li
Glad to help!