Skip Button ending conversation, instead of stopping on last dialogue element

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
need_verification
Posts: 24
Joined: Thu Jan 18, 2024 5:41 am

Skip Button ending conversation, instead of stopping on last dialogue element

Post by need_verification »

Hello I was following this post below on how to implement a skip button. How can I make it so it stop on the final dialogue element instead of auto-closing the conversation?

I want to implement this just in case the player presses skip by accident. Thank you Pixel Crushers!


https://www.pixelcrushers.com/phpbb/vie ... f=3&t=1196


I am using this script:

Code: Select all

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

public class SkipButton : MonoBehaviour
{

    public bool skip;

    private AbstractDialogueUI dialogueUI;

    private void Awake()
    {
        dialogueUI = GetComponentInChildren<AbstractDialogueUI>();
    }

    public void SkipToResponseMenu()
    {
        skip = true;
        dialogueUI.OnContinue();
    }

    void OnConversationLine(Subtitle subtitle)
    {
        if (skip) StartCoroutine(ContinueAtEndOfFrame());
    }

    IEnumerator ContinueAtEndOfFrame()
    {
        yield return new WaitForEndOfFrame();
        dialogueUI.OnContinue();
    }

    void OnConversationResponseMenu(Response[] responses)
    {
        skip = false;
    }
    void OnConversationEnd(Transform actor)
    {
        skip = false;
    }
}
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Tony Li »

Hi,

That post is close to 8 years old. You can use the Conversation Control component now. Add it to your Dialogue Manager or dialogue UI and configure a UI Button to call ConversationControl.SkipAll. If you want it to stop on the last line instead of skipping past it and ending the conversation, make a subclass that overrides OnConversationLine():

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (!DialogueManager.currentConversationState.hasAnyResponses) return;
        base.OnConversationLine(subtitle);
    }
}
need_verification
Posts: 24
Joined: Thu Jan 18, 2024 5:41 am

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by need_verification »

Tony Li wrote: Fri Jan 19, 2024 4:25 pm Hi,

That post is close to 8 years old. You can use the Conversation Control component now. Add it to your Dialogue Manager or dialogue UI and configure a UI Button to call ConversationControl.SkipAll. If you want it to stop on the last line instead of skipping past it and ending the conversation, make a subclass that overrides OnConversationLine():

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (!DialogueManager.currentConversationState.hasAnyResponses) return;
        base.OnConversationLine(subtitle);
    }
}
Thank you so much! It worked perfectly!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Tony Li »

Glad to help!
Saper
Posts: 43
Joined: Tue Jan 12, 2021 11:25 am

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Saper »

Hi Tony

I would like to add one more question to that subject. In ConversationControl.SkipAll code invoke sequences from all the Nodes, what I can do to run only sequneces in END Node?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Tony Li »

Hi,

First, use the current version of ConversationControl that will be in DS version 2.2.43:

DS_ConversationControl_2024-02-06.unitypackage

Then make a subclass of ConversationControl that skips all sequences except the final node's sequence if Skip All is set:

Code: Select all

public class MyConversationControl : ConversationControl
{
    public override void OnConversationLine(Subtitle subtitle)
    {
        if (skipAll && DialogueManager.currentConversationState.hasAnyResponses)
        {
            subtitle.sequence = "Continue()";
        }
        else
        {
            base.OnConversationLine(subtitle);
        }
     }
}
Saper
Posts: 43
Joined: Tue Jan 12, 2021 11:25 am

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Saper »

Hi Tony

After importing the script I have error:
Assets\Plugins\Pixel Crushers\Dialogue System\Scripts\UI\Utility\ConversationControl.cs(39,35): error CS0117: 'GameObjectUtility' does not contain a definition for 'FindFirstObjectByType'

We have Unity ver 2020.3.38f1 and FindFirstObjectByType is not implemented in this version

Code: Select all

        protected virtual void Awake()
        {
            dialogueUI =
                GetComponent<AbstractDialogueUI>() ??
                (DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
                GameObjectUtility.FindFirstObjectByType<AbstractDialogueUI>();
        }
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Tony Li »

Hi,

Can you back up your project and update to DS version 2.2.42, then import this unitypackage?
Saper
Posts: 43
Joined: Tue Jan 12, 2021 11:25 am

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Saper »

Hi Tony

after importing package we changed line 39 in ConversationControls.cs

From:

Code: Select all

 protected virtual void Awake()
        {
            dialogueUI =
                GetComponent<AbstractDialogueUI>() ??
                (DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
                GameObjectUtility.FindFirstObjectByType<AbstractDialogueUI>();
        }
To:

Code: Select all

        protected virtual void Awake()
        {
            dialogueUI = 
				GetComponent<AbstractDialogueUI>() ?? 
				(DialogueManager.standardDialogueUI as AbstractDialogueUI) ??
				FindObjectOfType<AbstractDialogueUI>();
        }
Code compile without errors and in game "skip dialogue" workig properly without any issue in console.
Right now we can't allow ourself to update DS (because time, and chance of something going side ways after update).
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Skip Button ending conversation, instead of stopping on last dialogue element

Post by Tony Li »

Hi,

That's absolutely fine. Unity 2023 will flag FindObjectOfType<T>() as being obsolete. That's why we introduced GameObjectUtility.FindFirstObjectByType<T>(). For earlier versions of Unity, FindObjectOfType<T>() works the same.
Post Reply