Page 1 of 1

Just want to detect conversation end

Posted: Fri Jul 28, 2023 3:30 pm
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?

Re: Just want to detect conversation end

Posted: Fri Jul 28, 2023 3:39 pm
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.

Re: Just want to detect conversation end

Posted: Fri Jul 28, 2023 3:42 pm
by LilGames
YES! Thank you.

Re: Just want to detect conversation end

Posted: Fri Jul 28, 2023 3:46 pm
by Tony Li
Happy to help!

Re: Just want to detect conversation end

Posted: Thu Aug 17, 2023 3:36 pm
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()); ?

Re: Just want to detect conversation end

Posted: Thu Aug 17, 2023 3:38 pm
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 !

Re: Just want to detect conversation end

Posted: Thu Aug 17, 2023 3:42 pm
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.)

Re: Just want to detect conversation end

Posted: Fri Aug 18, 2023 8:26 am
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 !

Re: Just want to detect conversation end

Posted: Fri Aug 18, 2023 8:49 am
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;
    }
}