Stop typewriter effect + show player responses (but do not force continue)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
tmeans825
Posts: 9
Joined: Sat Mar 27, 2021 5:32 pm

Stop typewriter effect + show player responses (but do not force continue)

Post by tmeans825 »

Hello!

My goal: I want to give players a way to skip/fast forward through the typewriter effect by pressing spacebar. I would like this to either:
  • finish out the current line of dialogue + immediately show the player response options, or (if no response options are between lines),
  • still force the player to click 'continue'. I have the continue button set to 'Not before Response Menu', in spirit of this.
I've been trying to figure out a solution to get somewhere inbetween what 'Cancel Subtitle' does, + just calling 'Stop()' on the typewriter effect.

Here are the issues with both approaches as they are today:

Cancel Subtitle:
If player has response options: This 'fast forwards' through the typewriter subtitle effect when an NPC is speaking, and immediately shows PC response options. Great!
If player does not have response options: this skips to the next line of dialogue without forcing the player to click the continue button. Sad!

Custom script that calls Stop() on the typewriter effect:
If player has response options: This 'fast forwards' the subtitle typewriter effect, but you still have to wait the full 'subtitle chars per second' before the player responses pop up. Sad!
If player does not have response options: this works great! Fast forwards through the typewriter effect, and the continue button is there and not skipped. Great!

Do you have an idea for a best approach here? Thank you!!
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by Tony Li »

For your custom script, you could call the dialogue UI's OnContinue() method so you don't need to wait for the full sequence duration.

However, a simpler, non-script approach would be to set the Continue Button mode to Optional Before Response Menu and use a continue button that has a StandardUIContinueButtonFastForward component on it. (All of the dialogue UI prefabs that ship with the Dialogue System are configured with StandardUIContinueButtonFastForward.) Then tick the Dialogue Manager GameObject's Input Device Manager component > Always Auto Focus checkbox to ensure that the continue button stays focused and responds to the space bar.
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by 2linescrossed »

Hey, I hope you don't mind me asking in this thread, but I've been having some issues of my own with the continue button's logic.
My current script is a pretty rough workaround - where, I attached a script to the UI where pressing spacebar activates the OnClick effect of the continue button so that the continue button doesn't have to visually be there - with the OnClick effect being the default StandardUIContinueButtonFastForward.

Setting the dialoguemanager to 'optional before response menu' breaks the logic completely, making me unable to progress the conversation at all, since the UI never shows up (Since I have a few blank nodes for sequencer functions) - and pressing spacebar doesn't do anything.
Setting it to Optional makes it work fine, except the issue is that this causes text inputs to break because people can accidentally spacebar THROUGH the text input.

In addition to this, I've been dealing with some inconsistency regarding the fast-forwarding - sometimes, the fast forwarding simply finishes the existing text, whereas other times it skips the typewriter effect entirely, moving into the next line before it has a chance to finish.
Ideally, I want it to be the prior all the time - a way to speed up reading the game for people, but one that isn't prone to skipping entire chunks of the script.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by Tony Li »

Hi,

The Unity UI EventSystem's Submit input is usually mapped to the space key. If the continue button has focus (i.e., is the EventSystem's current selection), then pressing the space key will issue a Submit input, which will click the continue button.

If your script manually invokes the button's OnClick() when you press space, that will result in a second click.

If you're not showing a visible continue button, you could get rid of it entirely. (But still keep the Dialogue Manager's Subtitle Settings > Continue Button mode to whatever you want it to be.) Instead of the visible continue button UI element, your script can either handle fast-forwarding itself -- if the subtitle panel's typewriter effect is playing, call its Stop() method; otherwise call the dialogue UI's OnContinue() -- or you can add a StandardUIContinueButtonFastForward component to the subtitle panel itself and your script can manually call its OnFastForward() method.
tmeans825
Posts: 9
Joined: Sat Mar 27, 2021 5:32 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by tmeans825 »

Thanks for the input so far! I think, to put another way, what I can't replicate using these methods is making the 'Continue' button functionally equivalent to a response menu when two NPCs are talking to each other. My hope is to replace all the player '...' conversation nodes below with a continue button (with the text of '...'):
Screenshot 2024-07-13 111354.png
Screenshot 2024-07-13 111354.png (11.77 KiB) Viewed 767 times
Requiring the player to press the 'continue' button exactly as if it is a response menu option, with the option to still fast forward the subtitle effect and subsequent display of the continue button or response menu via pressing space.

Using the fast forward component behaves differently if there is an upcoming response menu vs. just a continue button, so I can't get the exact functionality I'm looking for.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by Tony Li »

Hi,

Here's an example:

DS_ContinueLikeResponseExample_2024-07-13.unitypackage

Let's work off of this example. If it works the way you're looking for, you can set up your own UI similarly. If it doesn't work the way you want, please describe how you'd like it to work differently.
tmeans825
Posts: 9
Joined: Sat Mar 27, 2021 5:32 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by tmeans825 »

Thanks for putting this together!

The only difference with your example and what I'm looking for is that, in your example, you have click the continue button twice in a row before the response menu shows up. I only want the continue button to need to be pressed when there won't be a player response menu in between lines.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by Tony Li »

Hi,

In that case, use a small subclass of StandardUIContinueButtonFastForward. Here's an updated example scene:

DS_ContinueLikeResponseExample_2024-07-13-A.unitypackage

It uses this script:

Code: Select all

using PixelCrushers.DialogueSystem;
public class CustomContinueButtonFastForward : StandardUIContinueButtonFastForward
{
    public override void OnFastForward()
    {
        if (typewriterEffect.isPlaying)
        {
            var state = DialogueManager.currentConversationState;
            var isResponseMenuNext = state.hasPCResponses && !(state.hasPCAutoResponse || state.hasNPCResponse);
            if (isResponseMenuNext) typewriterEffect.Stop();
        }
        base.OnFastForward();
    }
}
2linescrossed
Posts: 47
Joined: Tue May 16, 2023 10:37 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by 2linescrossed »

Tony Li wrote: Fri Jul 12, 2024 9:34 am Hi,

The Unity UI EventSystem's Submit input is usually mapped to the space key. If the continue button has focus (i.e., is the EventSystem's current selection), then pressing the space key will issue a Submit input, which will click the continue button.

If your script manually invokes the button's OnClick() when you press space, that will result in a second click.

If you're not showing a visible continue button, you could get rid of it entirely. (But still keep the Dialogue Manager's Subtitle Settings > Continue Button mode to whatever you want it to be.) Instead of the visible continue button UI element, your script can either handle fast-forwarding itself -- if the subtitle panel's typewriter effect is playing, call its Stop() method; otherwise call the dialogue UI's OnContinue() -- or you can add a StandardUIContinueButtonFastForward component to the subtitle panel itself and your script can manually call its OnFastForward() method.

Hey Tony, still playing around with this. I removed the calls to the second input - but the issue where I have inconsistent Dialogue displaying is still present. Sometimes Spacebar skips text entirely, other times it requires two taps like I want it to. I'm very unsure why this happens, as it only sometimes does what I want it to do - autocompleting text if it hasn't finished typing, and skipping once it has. As far as I can tell, I've reverted the continue button changes (in fact, the continue button is inactive in the modified standard UI), but it still seems to be skipping on spacebar presses. Can you recommend any fixes? I'm not sure how the Continue Optional setting in the DialogueManager handles the stop and OnContinue functions for the conversation.
User avatar
Tony Li
Posts: 21962
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop typewriter effect + show player responses (but do not force continue)

Post by Tony Li »

Hi,

If you've assigned anything to the Dialogue Manager's Display Settings > Input Settings > Cancel Subtitle Input or Cancel Conversation Input, I recommend clearing them. Set the Key dropdown to None, and clear the Button field. This way the only inputs that will affect continuation of the typewriter/subtitle are:

1. The EventSystem clicks the continue button. This will happen if the EventSystem thinks the continue button is selected and you press the EventSystem's Submit input (normally mapped to Space).

2. Or if the continue button has a UI Button Key Trigger component and you press the key or button input assigned to it.

3. Or some other script of your own, if present?

(And also if the Sequence has ended and the conversation isn't configured to require continue button presses -- e.g., the Continue Button dropdown is set to Never.)

If that info doesn't help, please feel free to send a reproduction project to tony (at) pixelcrushers.com
Post Reply