How to pause the game when the dialogue is shown

Announcements, support questions, and discussion for the Dialogue System.
NotoMuteki
Posts: 17
Joined: Mon Oct 11, 2021 9:48 pm

Re: How to pause the game when the dialogue is shown

Post by NotoMuteki »

Thank you!



Now "Continue" button works fine, when it pushed the substitute gets hidden, resumes timeline, but the conversation doesn't proceed.
And after the timeline passed Conversation Continue Clip, it proceeds to the next entry.

The last problem is the Response Menu Button.
This also proceeds to the next entry automatically, so some code will be needed.
I tried the same way with Continue button(attach "ContinueButtonResumeSpeakerTimeline" script on "Response Button Template", set "ClickedContinueButton()" as OnClick list), but it didn't go well.
The timeline resumes, but the Response menu doesn't disappear.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to pause the game when the dialogue is shown

Post by Tony Li »

Hi,

I don't understand. In your video, the response menu looks like it correctly disappears as soon as you click a response menu button.
NotoMuteki
Posts: 17
Joined: Mon Oct 11, 2021 9:48 pm

Re: How to pause the game when the dialogue is shown

Post by NotoMuteki »

Sorry, lack of explanations.
The video is before I attached ContinueButtonResumeSpeakerTimeline script by my own.
As you can see in the video, after the response was selected it proceeds to the next entry automatically regardless of next clip’s position.
So I attached your code to Response button just like Continue button, but in the result response menu won’t disappear.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to pause the game when the dialogue is shown

Post by Tony Li »

Thanks. I think I understand now. When you click a response button, it always advances to the next step in the conversation.

To change this, you will need to change the response button so it does three things:
  • Record which button was clicked
  • Do not tell the Dialogue System which button was clicked yet
  • Hide the menu panel
Instead of using ContinueButtonResumeSpeakerTimeline, add this script to your response button template. Configure the button's OnClick() UnityEvent to call the script's ClickedResponseButton() method:

ResponseButtonResumeSpeakerTimeline.cs

Code: Select all

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
using PixelCrushers.DialogueSystem;

public class ResponseButtonResumeSpeakerTimeline : MonoBehaviour
{
    public static StandardUIResponseButton buttonThatWasClicked;

    public void ClickedResponseButton()
    {
        // Record which button was clicked, but don't tell the Dialogue System yet:
        buttonThatWasClicked = GetComponent<StandardUIResponseButton>(); // EDIT: Fixed typo.
        // Resume timeline:
        var playableDirector = DialogueManager.currentConversant.GetComponent<PlayableDirector>();
        if (playableDirector != null) playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(1);
        else Debug.LogWarning("ResponseButtonResumeSpeakerTimeline: No timeline found on " + DialogueManager.currentConversant);
        // Hide the menu panel:
        DialogueManager.standardDialogueUI.conversationUIElements.defaultMenuPanel.Close();        
    }
}
Later in the timeline, when you're ready to advance the conversation, tell the Dialogue System which button was clicked. You will need some code to do this. You could write a custom clip that

Code: Select all

public void UseButtonThatWasClicked()
{
    ResponseButtonResumeSpeakerTimeline.buttonThatWasClicked.OnClick();
}
NotoMuteki
Posts: 17
Joined: Mon Oct 11, 2021 9:48 pm

Re: How to pause the game when the dialogue is shown

Post by NotoMuteki »

Thank you.

First, your ResponseButtonResumeSpeakerTimeline.cs had compile error.

Code: Select all

Assets\Game\DSTest\ResponseButtonResumeSpeakerTimeline.cs(11,32): error CS0029: Cannot implicitly convert type 'ResponseButtonResumeSpeakerTimeline' to 'PixelCrushers.DialogueSystem.StandardUIResponseButton'
In line 11,

Code: Select all

buttonThatWasClicked = this;
"this;" was causing the error so I changed to

Code: Select all

buttonThatWasClicked = GetComponent<StandardUIResponseButton>();
Is this wrong?

Then I attached ResponseButtonResumeSpeakerTimeline.cs to response button template and configured.
ResponseButton.png
ResponseButton.png (153.49 KiB) Viewed 684 times
Then I wrote 2 scripts to create custom track that inherit normal Continue Conversation Clip but tells the Dialogue System which button was clicked,

ContinueConversationAfterResponseBehaviour.cs

Code: Select all

#if USE_TIMELINE
#if UNITY_2017_1_OR_NEWER
// Copyright (c) Pixel Crushers. All rights reserved.

using UnityEngine;
using UnityEngine.Playables;
using System;

namespace PixelCrushers.DialogueSystem
{
    public class ContinueConversationAfterResponseBehaviour : ContinueConversationBehaviour
    {
        public void UseButtonThatWasClicked()
        {
            ResponseButtonResumeSpeakerTimeline.buttonThatWasClicked.OnClick();
        }
    }

}
#endif
#endif
ContinueConversationAfterResponseClip.cs

Code: Select all

using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;


namespace PixelCrushers.DialogueSystem
{
    [Serializable]
    public class ContinueConversationAfterResponseClip : ContinueConversationClip
    {

        public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
        {
            var playable = ScriptPlayable<ContinueConversationAfterResponseBehaviour>.Create(graph);

            return playable;
        }
    }
}
And I put ContinueConversationAfterResponseClip on the third phrase(which is actually the conversation after the player answered.)
Timeline.png
Timeline.png (228.79 KiB) Viewed 684 times
Here's the result:


The timeline doesn't go back to speed 1, so I can't even confirm my new custom clip is working fine or not.
I tested some codes in Default Response Menu Sequence like;

Code: Select all

Timeline(speed, speaker, 0)@Message(Responded);

Code: Select all

Timeline(speed, speaker, 0)@Message(OnClick);
but none of these worked to set the speed of timeline back to 1.
Honestly I have no idea what message were sent by Response script, and how to search it in manual.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to pause the game when the dialogue is shown

Post by Tony Li »

Hi,

In my previous post, I forgot to include the code to resume the timeline. I just updated that post. Please look at the updated script in the post.
NotoMuteki
Posts: 17
Joined: Mon Oct 11, 2021 9:48 pm

Re: How to pause the game when the dialogue is shown

Post by NotoMuteki »

Thank you.
I updated your code and here's the result:



Thanks for your code added, now the timeline resumes after the player pushed response button.
(The animation of Response menu looks little strange like it's doubling though...)
But at the next ContinueConversationAfterResponseClip(the custom clip I made in the last post, codes are above),
the conversation doesn't progress.
I think my implementation on custom clip was quite wrong, but I don't know much about the custom track.
In ContinueConversationAfterResponseBehaviour.cs,

Code: Select all

        public void UseButtonThatWasClicked()
        {
            ResponseButtonResumeSpeakerTimeline.buttonThatWasClicked.OnClick();
        }
I think this method wasn't called by anyone, so the DS couldn't receive the response and progress the conversation.
How and where should I call this method to pass the response to DS?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to pause the game when the dialogue is shown

Post by Tony Li »

Hi,

Your custom clip will require 4 scripts, including a mixer behaviour. It might look something like this:

Code: Select all

public class ContinueConversationMixerBehaviour : PlayableBehaviour
{

    // NOTE: This function is called at runtime and edit time.  Keep that in mind when setting the values of properties.
    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        if (Application.isPlaying) ResponseButtonResumeSpeakerTimeline.buttonThatWasClicked.OnClick();
    }
}
For an example, look at the Continue Conversation clip's scripts in Plugins / Pixel Crushers / Dialogue System / Scripts / Options / Timeline / Playables / Continue.
NotoMuteki
Posts: 17
Joined: Mon Oct 11, 2021 9:48 pm

Re: How to pause the game when the dialogue is shown

Post by NotoMuteki »

I wrote the script ContinueConversationAfterResponseBehaviour.cs like this:

Code: Select all

#if USE_TIMELINE
#if UNITY_2017_1_OR_NEWER
// Copyright (c) Pixel Crushers. All rights reserved.

using UnityEngine;
using UnityEngine.Playables;
using System;

namespace PixelCrushers.DialogueSystem
{
    public class ContinueConversationAfterResponseBehaviour : ContinueConversationBehaviour
    {
        public void UseButtonThatWasClicked()
        {
            ResponseButtonResumeSpeakerTimeline.buttonThatWasClicked.OnClick();
        }
    }

}
#endif
#endif
But the result was same as before I've posted in the last reply. I just doesn't proceeds the conversation.

I created repro scene and packed in .unitypackage file.

The test scene is at Assets/Game/DSTest/OutdoorsScene.unity
Please play the timeline and see what's wrong with Custom clip.
My project is HDRP, so If you open it up in URP the materials won’t work.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to pause the game when the dialogue is shown

Post by Tony Li »

Hi,

I updated your ContinueConversationAfterResponse clip scripts. Timeline clips require 4 scripts:

DS_ContinueConversationAfterResponse_TimelineClip_2021-10-19.unitypackage

To use it, add another track for your ContinueConversationAfterResponse clips:

continueTimeline.png
continueTimeline.png (42.58 KiB) Viewed 664 times

You may also want to configure the response menu to hide the NPC Subtitle Panel when the response menu closes:

continueTimelineUI.png
continueTimelineUI.png (49.42 KiB) Viewed 664 times
Post Reply