Problems when trying to open / change dialogu ui via code

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Khang
Posts: 1
Joined: Tue Aug 06, 2024 3:09 pm

Problems when trying to open / change dialogu ui via code

Post 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?
User avatar
Tony Li
Posts: 22001
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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().
Post Reply