Just want to detect conversation end

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LilGames
Posts: 29
Joined: Fri Jul 07, 2023 6:38 pm

Just want to detect conversation end

Post by LilGames »

Hi. Maybe I'm being a bit naive here, but I'm implementing Dialogue System in a really simple way: I trigger a conversation directly by specifying the conversation string name; eg:
DialogueManager.StartConversation(convoName);

What I was initially expecting was a callback parameter, but apparently there is none. eg:
DialogueManager.StartConversation(convoName, conversationEndedCallBack);

So next I found and read up about the event, "OnConversationEnd" but again, it doesn't seem simple or I'm doing something wrong. I was hoping I could just subscribe a Delegate like this:
OnConversationEnd += MyConversationEnded;

or OnSequenceEnd but I can't seem to figure out the namespace for such an event.

My code is in a scene that will launch all Dialogues directly and there is no "gameObject" Actor. What do I do?
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Just want to detect conversation end

Post by Tony Li »

Hi,

If you want a C# event, use DialogueManager.instance.conversationEnded. Example:

Code: Select all

DialogueManager.instance.conversationEnded += OnConversationEnded;
DialogueManager.StartConversation(convoName);
...
void OnConversationEnded(Transform actor)
{
    DialogueManager.instance.conversationEnded += OnConversationEnded;
    Debug.Log(DialogueManager.lastConversationStarted + " ended.");
}
If you don't want to bother with C# events, add an OnConversationEnd(Transform) method to any script in your Dialogue Manager hierarchy or a conversation participant. If you add it to the Dialogue Manager, it will be invoked by all conversations. If you add it to a participant, it will only be invoked when the participant is the conversation's actor or conversant.

And if you don't want to bother with scripting at all, add a Dialogue System Events component to your Dialogue Manager or a conversation participant, and configure the OnConversationEnd() UnityEvent.
LilGames
Posts: 29
Joined: Fri Jul 07, 2023 6:38 pm

Re: Just want to detect conversation end

Post by LilGames »

YES! Thank you.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Just want to detect conversation end

Post by Tony Li »

Happy to help!
KNGKRMSN
Posts: 8
Joined: Tue Aug 08, 2023 6:14 am

Re: Just want to detect conversation end

Post by KNGKRMSN »

Hi, sorry to up this old thread, but I wondered the same thing but while trying to play an animation from the Camera & Cutscenes Settings. Can I do something like required AnimatorPlay(Idle, speakerportrait)@Message(OnConversationEnd()); ?
KNGKRMSN
Posts: 8
Joined: Tue Aug 08, 2023 6:14 am

Re: Just want to detect conversation end

Post by KNGKRMSN »

Well, now that I think about it, I'd want it to trigger right when the last option of dialogue is clicked, just before the dialogue ends. Sorry and thanks in advance !
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Just want to detect conversation end

Post by Tony Li »

Usually idle (and, for example, talk) animations are played through the Default Sequence like this:

Code: Select all

AnimatorPlay(talk, speakerportrait);
required AnimatorPlay(idle, speakerportrait)@{{end}}
or:

Code: Select all

AnimatorPlay(talk, speakerportrait);
required AnimatorPlay(idle, speakerportrait)@Message(Typed)
The first sequence above goes to idle after a duration determined by the text length and the Dialogue Manager's Subtitle Settings > Subtitle Chars Per Second.

The second sequence is similar, but it goes to idle when the typewriter effect has finished. (The typewriter automatically sends the sequencer message "Typed" when it's done.)
KNGKRMSN
Posts: 8
Joined: Tue Aug 08, 2023 6:14 am

Re: Just want to detect conversation end

Post by KNGKRMSN »

Thanks, but I must have formulated my question poorly. Id like to detect when the whole conversation ends, not just the end of a dialogue line. I have an animation to make disappear the speaker portrait and the player portrait, and would like it to play just as the players selects the last dialogue option, the one that close the conversation. Thanks again for your time !
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Just want to detect conversation end

Post by Tony Li »

Hi,

To detect when a conversation has fully ended, use a Dialogue System Events component (OnConversationEnd event), DialogueManager.instance.conversationEnded C# event, or OnConversationEnd(Transform) script method. However, that this point the dialogue UI will have deactivated the speakerportrait.

Instead, you will probably want to know when the final dialogue entry is about to play, not when the entire conversation has ended. Here are two ways to do this:

1. Add an empty node at the end. Put your sequence in that node.

2. Or use an OnConversationLine(Subtitle) method. In it, check if this is the final node. If so, add your sequence to the subtitle's sequence:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    if (!DialogueManager.currentConversationState.hasAnyResponses)
    {
        subtitle.sequence = @"AnimatorPlay(talk, speakerportrait); required AnimatorPlay(idle, speakerportrait)@{{end}}; " + subtitle.sequence;
    }
}
Post Reply