Page 1 of 1

Problems when trying to open / change dialogu ui via code

Posted: Tue Aug 06, 2024 3:16 pm
by Khang
Hi,

I am trying to use questmachine for my game. However i want to trigger the dialogue at certain points in the game via code to continue with the story while the player runs around.

However, i am facing problems trying to open and update the dialogue UI via code.

i am using custom srt files to have the text updated and synced with the voice over.
For that i am sending a message with the srt file as parameter instead of using the dialogue box.

Now i am facing these problems:

1. The text in the dialogueui is not updated using:

Code: Select all

_dialogueUI.bodyTemplate.Assign(srtFileContent);
2. I am getting a null ref when passing the questjournal gameobject to the speaker:

Code: Select all

_currentSpeaker.StartDialogue(QuestManager.instance.gameObject);
This is my (simplified) code:

Code: Select all

    
    public void OnGreetMessageSend(MessageArgs messageArgs)
    {
         _currentSpeaker = QuestMachineMessages.FindGameObjectWithID(messageArgs.sender.ToString()).GetComponent<QuestGiver>();

         //todo not working for some reason:
         //_currentSpeaker.StartDialogue(QuestManager.instance.gameObject);
         
         _dialogueUI.Show();
         ProcessSRTFile(messageArgs.parameter);
    }

    private void ProcessSRTFile(string srtFileContent)
    {
        _dialogueUI.bodyTemplate.Assign(srtFileContent);
        _dialogueUI.Hide();
    }
Am i missing something or is there perhaps a smarter way to make the dialogue UI appear when i update the dialogue box in a node?

Re: Problems when trying to open / change dialogu ui via code

Posted: Tue Aug 06, 2024 5:14 pm
by Tony Li
Hi,

> 1. The text in the dialogueui is not updated using: <code>

To update the text, I recommend making a subclass of UnityUIQuestDialogueUI and using that on your quest dialogue UI instead of the original class. (See this post to replace it in-place and keep UI element assignments.)

Override the AddBodyContent and AddHeadingContent methods.


> 2. I am getting a null ref when passing the questjournal gameobject to the speaker:

This would only work if your QuestJournal component is actually on the Quest Machine GameObject. A better way to get a reference to the QuestJournal is the function QuestMachine.GetQuestJournal().