Fixed time delay between dialogue entries

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

Fixed time delay between dialogue entries

Post by Abelius »

I made a quick search and didn't find a relevant thread.

I was wondering if there is a way to introduce an artificial delay between two dialogue entries. That is, making DS wait after the Continue() of the previous entry, before starting to execute the next one. Something like a given amount of time (0.016 sec) or a frame would be enough, I think.

It's not for story-telling purposes, but for making sure the rest of my engine has time to execute things in the background.

If this requires a change in DS, of course I don't expect you to modify this for every user. Telling me what should I change in the scripts would be more than enough.

Thanks!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fixed time delay between dialogue entries

Post by Tony Li »

Hi,

No need to change any Dialogue System scripts. If you're using StandardUIContinueButtonFastForward on your continue button, you can replace it with a subclass like this:

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CustomStandardUIContinueButtonFastForward : StandardUIContinueButtonFastForward
{
    public override void OnFastForward()
    {
        if ((typewriterEffect != null) && typewriterEffect.isPlaying)
        {
            base.OnFastForward();
        }
        else
        {
            StartCoroutine(ContinueAfterDelay());
        }
    }
    
    IEnumerator ContinueAfterDelay()
    {
        continueButton.gameObject.SetActive(false);
        yield return null; // <-- Delay 1 frame. Change if you want to delay longer.
        base.OnFastForward();
    }
}
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

Re: Fixed time delay between dialogue entries

Post by Abelius »

Hi Tony, thanks for the fast reply.

This could work with player clicks and the "press Ctrl to skip" feature I have, yes, but what about entries with a Continue() command in the Sequence field? Will those call OnFastForward() as well, so the delay could be applied?

The thing is, your plugin is so awesome that I'm using DS for a lot more than just dialogue. I have a lot of nodes that execute sequence commands with a Continue() at the end, so they run pretty fast and sequentially. Therefore, it would be a bit safer if DS would add that delay in between, regardless if the continuing has been done by the player or not.

Also, in case the answer to the previous is yes, how could I wait for a fixed amount of time instead of a frame?

P.S.: I'm also getting this...
Image
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fixed time delay between dialogue entries

Post by Tony Li »

To delay for a fixed time such as 0.25 seconds, change:

Code: Select all

yield return null;
to:

Code: Select all

yield return new WaitForSeconds(0.25f);
Instead of the continue button subclass, try adding this script to the Dialogue Manager:

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CustomFinishSubtitleScript : MonoBehaviour
{
    void OnConversationStart(Transform actor)
    {
        DialogueManager.conversationView.FinishedSubtitleHandler -= 
    DialogueManager.conversationController.OnFinishedSubtitle;
        DialogueManager.conversationView.FinishedSubtitleHandler += DelayThenFinishSubtitle
    }

    void DelayThenFinishSubtitle(object sender, EventArgs e)
    {
        StartCoroutine(FinishSubtitleAfterDelay(sender, e);
    }

    IEnumerator FinishSubtitleAfterDelay(object sender, EventArgs e)
    {
        yield return new WaitForSeconds(0.25f);
        DialogueManager.conversationController.OnFinishedSubtitle(sender, e);
    }
}
I'm in the middle of a project launch at the moment so I didn't have time to test it. It might have some issues, but that's the general idea.
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

Re: Fixed time delay between dialogue entries

Post by Abelius »

Thank you so much, Tony. I appreciate your time!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fixed time delay between dialogue entries

Post by Tony Li »

Glad to help! If it doesn't work, let me know. I typed it directly into the reply, so it might have typos.
User avatar
Abelius
Posts: 312
Joined: Fri Jul 21, 2017 12:45 pm

Re: Fixed time delay between dialogue entries

Post by Abelius »

Yup, I just needed to add a line and some semicolons. All good.

I also added a public float to change the waiting time on demand. I'll leave it here in case someone is interested.

Code: Select all

using System;
using System.Collections;
using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CustomFinishSubtitleScript : MonoBehaviour
{

    public float timeDelay = 0.016f;

    void OnConversationStart(Transform actor)
    {
        DialogueManager.conversationView.FinishedSubtitleHandler -=
    DialogueManager.conversationController.OnFinishedSubtitle;
        DialogueManager.conversationView.FinishedSubtitleHandler += DelayThenFinishSubtitle;
    }

    void DelayThenFinishSubtitle(object sender, EventArgs e)
    {
        StartCoroutine(FinishSubtitleAfterDelay(sender, e));
    }

    IEnumerator FinishSubtitleAfterDelay(object sender, System.EventArgs e)
    {
        yield return new WaitForSeconds(timeDelay);
        DialogueManager.conversationController.OnFinishedSubtitle(sender, e);
    }
}
Thanks!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Fixed time delay between dialogue entries

Post by Tony Li »

Thanks for fixing and sharing the code!
Post Reply