Page 1 of 1

[Solved] Run method on actor change

Posted: Sun Feb 13, 2022 10:07 am
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? :)

Re: Run method on actor change

Posted: Sun Feb 13, 2022 10:45 am
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.

Re: Run method on actor change

Posted: Sun Feb 13, 2022 11:37 am
by sawiyon
worked, thanks a lot! :)

Re: [Solved] Run method on actor change

Posted: Sun Feb 13, 2022 1:39 pm
by Tony Li
Happy to help!