Update NPC TMPro.text using sequencer

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Update NPC TMPro.text using sequencer

Post by domopuff »

Hey Tony,

I'm trying to change the text of the TMPro component on an NPC via the sequencer by means of inputting a string in the sequencer. So I'm looking at something like this, SetTMPUI(NPCText, string).

I saw this on the forum but this required a preexisting Dialogue Manager variable to assign. I was trying to customize it to take in the string but failed to do so. As such, I was wondering if you know of a way I can go about doing this!
Tony Li wrote: Mon Nov 23, 2020 10:18 am Hi Keiji,

You can do both in one sequencer command:

SequencerCommandSetTMPUI.cs

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    // Syntax: SetTMPUI(TMPObjectName, VariableName)
    public class SequencerCommandSetTMPUI : SequencerCommand
    {
        private void Awake()
        {
            var tmpObject = GetSubject(0);
            var variableName = GetParameter(1);
            if (tmpObject == null)
            {
                Debug.LogWarning("SetTMPUI(): Can't find GameObject '" + GetParameter(0) + "'");
            }
            else if (string.IsNullOrEmpty(variableName) || !DialogueLua.DoesVariableExist(variableName))
            {
                Debug.LogWarning("SetTMPUI(): There is no variable named '" + variableName + "'");
            }
            else
            {
                var variableValue = DialogueLua.GetVariable(variableName).asString;
                var tmp = tmpObject.GetComponent<TextMeshPro>();
                var tmpUGUI = tmpObject.GetComponent<TextMeshProUGUI>();
                if (tmp != null)
                {
                    tmp.text = variableValue;
                }
                else if (tmpUGUI != null)
                {
                    tmpUGUI.text = variableValue;
                }
                else
                {
                    Debug.LogWarning("SetTMPUI(): No TextMesh Pro component found on " + tmpObject, tmpObject);
                }
            }
            Stop();
        }
    }
}


Thank you, love your package man. It enabled me to do so much more!
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Re: Update NPC TMPro.text using sequencer

Post by domopuff »

Also, I'm having two difficulties with my project.

Since I'm using responses for my conversations, my sequencer commands do not play at the start during the conversation trigger but rather after. I've tested it for the response menu sequence as well and likewise, it doesn't play from the start. Not sure if you know any way I can get around this, or have the sequencer play the moment the response menu is activated?

The second difficulty is trying to get the NavMeshAgent(destination, AINpc)-> Message(Arrived); command to send a message after it's done arriving. It always seems to send the message at the instance it starts playing rather than at the arrival state.
My follow-up action will be AnimatorPlay(state name, NPC)@Message(Arrived).

I'm guessing this has to do with the response menu? Perhaps I can find your thoughts or solutions to this!
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Update NPC TMPro.text using sequencer

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!
domopuff wrote: Sat Jun 18, 2022 10:41 pmI'm trying to change the text of the TMPro component on an NPC via the sequencer by means of inputting a string in the sequencer. So I'm looking at something like this, SetTMPUI(NPCText, string). [Cut SequencerCommandSetTMPUI.cs example]
How are you inputting a string? Can you use the TextInput() sequencer command? If so, this will set a DS variable value. You could them use that custom SetTMPUI() sequencer command to show the variable value.
domopuff wrote: Sun Jun 19, 2022 12:07 amSince I'm using responses for my conversations, my sequencer commands do not play at the start during the conversation trigger but rather after. I've tested it for the response menu sequence as well and likewise, it doesn't play from the start. Not sure if you know any way I can get around this, or have the sequencer play the moment the response menu is activated?
What if you add a Response Menu Sequence to the NPC node that precedes the response menu?
domopuff wrote: Sun Jun 19, 2022 12:07 amThe second difficulty is trying to get the NavMeshAgent(destination, AINpc)-> Message(Arrived); command to send a message after it's done arriving. It always seems to send the message at the instance it starts playing rather than at the arrival state.
My follow-up action will be AnimatorPlay(state name, NPC)@Message(Arrived).
The NavMeshAgent() sequencer command just sets the destination; it doesn't wait for the agent to reach the destination. You could try the NavMeshDestination() sequencer command from this forum post.
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Re: Update NPC TMPro.text using sequencer

Post by domopuff »

Thanks for the suggestion Tony!

For the string query, I went ahead with creating a DS variable and used the SetVariable to update the NPC dialogue text while referencing the DS variable.

For the response menu, I think that works but I think I wanted to find out why the sequencers or the response menu sequence don't play at the start but rather after the response node is selected.

Will try the NavMeshAgent script you mentioned!

Thanks again Tony!
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Update NPC TMPro.text using sequencer

Post by Tony Li »

For the response sequences, that's by design. For example, say the responses presented to the player are to enter Door 1, Door 2, or Door 3:

enterDoorResponseMenu.png
enterDoorResponseMenu.png (10.87 KiB) Viewed 489 times

And say the sequence on each response animates the player to enter the corresponding door. You wouldn't want to play any of those sequences until the player chooses which door to enter.

If you want to play a sequence while the response menu is visible and waiting for the player to choose a response, that's what the Response Menu Sequence is for. For example, the Response Menu Sequence could animate the NPC to boredly look around the room and tap her foot while waiting for the player to choose a response.
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Re: Update NPC TMPro.text using sequencer

Post by domopuff »

I understand now. Thanks for your help Tony!
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Update NPC TMPro.text using sequencer

Post by Tony Li »

Happy to help!
Post Reply