[Solved] Run method on actor change

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
sawiyon
Posts: 5
Joined: Sun Feb 13, 2022 9:58 am

[Solved] Run method on actor change

Post by sawiyon »

Heya, I have a quick question!

Is it possible to run a specific method each time the actor (speaker of the entry) changes during a conversation? :)
Last edited by sawiyon on Sun Feb 13, 2022 11:37 am, edited 1 time in total.
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Run method on actor change

Post by Tony Li »

Hi,

To do it manually, you can use sequencer commands or scene events.

To do it automatically, add a script with an OnConversationLine method to the Dialogue Manager. Example:

Code: Select all

Transform currentSpeakerTransform = null;
...
void OnConversationLine(Subtitle subtitle)
{
    if (subtitle.speakerInfo.transform != currentSpeakerTransform)
    {
        currentSpeakerTransform = subtitle.speakerInfo.transform;
        Debug.Log("New speaker: " + subtitle.speakerInfo.Name);
    }
}
Depending on your needs, you may want to skip this if there's no text (string.IsNullOrEmpty(subtitle.formattedText.text)), or for player lines (subtitle.speakerInfo.isPlayer), etc.
sawiyon
Posts: 5
Joined: Sun Feb 13, 2022 9:58 am

Re: Run method on actor change

Post by sawiyon »

worked, thanks a lot! :)
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: [Solved] Run method on actor change

Post by Tony Li »

Happy to help!
Post Reply