Typewriter Effect One Frame Delay Causes Flicker?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Unrighteous
Posts: 36
Joined: Thu Mar 17, 2022 5:32 pm

Typewriter Effect One Frame Delay Causes Flicker?

Post by Unrighteous »

Hello,

I've been struggling to figure out a solution to this for a while, and was hoping I could get some help.

Basically, I have a TextMeshProTypewritterEffect component for Subtitle Text, and I need the "Wait One Frame Before Starting" box to be checked. The issue is that checking this box causes the text to appear for a split second (whenever a new line of dialogue is shown), then disappear and typewrite normally. This flickering effect doesn't look nice, and I'm searching for a solution to it.

Is there a way to call code at the start of a line of dialogue? I was thinking I could set the text alpha to 0 at the start of the line, and then set it back to 1 when the typewriter begins the next frame.


The reason I need the "Wait One Frame Before Starting" option is because I have a custom script that sets a different "Audio Clip" for the typewriter depending on which character is speaking (I look at the portrait name for this), and it only works if the typewriter waits a frame. I've tried changing the execution order of my script as well as a few others, but I can't get it to work correctly. Waiting a frame seems to be the only way.

Any help is greatly appreciated, thank you.

Unity 2020.3.33f1
Dialogue System 2.2.27
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Typewriter Effect One Frame Delay Causes Flicker?

Post by Tony Li »

Hi,

You should be able to untick "Wait One Frame Before Starting" if you set the audio clip in an OnConversationLine method, which is called before the typewriter is set up. Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    DialogueActor dialogueActor;
    var panel = DialogueManager.standardDialogueUI.conversationUIElements.standardSubtitleControls.GetPanel(subtitle, out dialogueActor);
    typewriterEffect = panel.subtitleText.GetComponent<AbstractTypewriterEffect>();
    typewriterEffect.audioClip = // set clip here. Maybe using subtitle.speakerInfo?
}
Unrighteous
Posts: 36
Joined: Thu Mar 17, 2022 5:32 pm

Re: Typewriter Effect One Frame Delay Causes Flicker?

Post by Unrighteous »

Hello, thank you for the response!

Unfortunately, similar to what I was experiencing when I set my script's execution order to the top of the list, calling my script's methods through OnConversationLine() always gets the previous speaker, not the current one. I'm still not sure why this is. I'm getting a string from the Portrait Name object's text component to identify the speaker, maybe that has something to do with it.

Fortunately, using OnConversationLine() to make the subtitle text invisible, and then making it visible again the next frame using the Subtitle Text object's OnBegin() method works like a charm.

I didn't know about the OnConversationLine() method, I'll have to dig a bit deeper next time I'm stuck.

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

Re: Typewriter Effect One Frame Delay Causes Flicker?

Post by Tony Li »

Hi,

OnConversationLine(Subtitle) is called before the subtitle panel is set up. Instead, use the Subtitle object that's passed to OnConversationLine(). It contains all of the information you should need about the upcoming subtitle. The speaker's info is in the speakerInfo property:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    Debug.Log($"{subtitle.speakerInfo.Name} (database name {subtitle.speakerInfo.nameInDatabase}) is about to talk.");
}
Unrighteous
Posts: 36
Joined: Thu Mar 17, 2022 5:32 pm

Re: Typewriter Effect One Frame Delay Causes Flicker?

Post by Unrighteous »

Aha! That makes much more sense, I got it working properly now. This is much nicer than the weird hiding/unhiding the subtitle text I was doing before, and now I don't need to bother getting the character names from the Portrait Name object.

I'm an amateur when it comes to coding, so I didn't grasp this at first; thanks for being patient with me, and thanks again for all the help!
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Typewriter Effect One Frame Delay Causes Flicker?

Post by Tony Li »

Glad to help!
Post Reply