Stop and Start conversation in a same frame

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Stop and Start conversation in a same frame

Post by fkkcloud »

Hello,

I am stopping a conversation with Override Dialogue UI and starting a conversation with non-override dialogue UI (default dialogue UI).
The latter conversation should use the default dialogue UI has no Override Dialogue UI component in any of actor/speaker/conversant in the conversation. Conversation info/setting in the inspector does not have any Override setting as well.

Below is sequence command that I am using to call/switch the conversation.

Code: Select all

public class SequencerCommandAmberAlert : SequencerCommand
    {
        public void Awake()
        {
            PixelCrushers.UIPanel.monitorSelection = false;

            StartCoroutine(coroutine_StartAmberAlert());
        }

        IEnumerator coroutine_StartAmberAlert()
        {
            GameObject obj = GameObject.Find("SMS_Dialogue_Panel");
            Debug.Log("object found:" + obj);
            if (obj)
            {
                Animator SMS_ScreenEventAnimator = obj.GetComponent<Animator>();
                Debug.Log("object found:" + SMS_ScreenEventAnimator);
                if (SMS_ScreenEventAnimator)
                {
                    SMS_ScreenEventAnimator.SetTrigger("AmberAlert");
                }
            }

            yield return new WaitForSeconds(5); // wait until the animation end.
            
            DialogueManager.StopConversation();

            GameManager.Instance.eventSystemModule.enabled = true;
            PixelCrushers.UIPanel.monitorSelection = true;
            DialogueManager.StartConversation("Ch01_Intro01_Apt_Scn_05_B");

            Stop();
        }
    }

and calling it in sequence

Code: Select all

SetInput(false);
AmberAlert()@1;
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop and Start conversation in a same frame

Post by Tony Li »

Thanks for sharing!
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Stop and Start conversation in a same frame

Post by fkkcloud »

Hello!

I meant it is not working. It still uses the previous conversation's Dialogue UI which was override!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop and Start conversation in a same frame

Post by Tony Li »

Can you try waiting 1 frame?

Code: Select all

            yield return new WaitForSeconds(5); // wait until the animation end.
            
            DialogueManager.StopConversation();
            
            yield return null; //<--- ADD THIS.

            GameManager.Instance.eventSystemModule.enabled = true;
            PixelCrushers.UIPanel.monitorSelection = true;
            DialogueManager.StartConversation("Ch01_Intro01_Apt_Scn_05_B");

            Stop();
If that doesn't work, can you please send a reproduction project to tony (at) pixelcrushers.com?
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Stop and Start conversation in a same frame

Post by fkkcloud »

Still no luck.

As I Stop the conversation who is the owner of the sequencer command, the coroutine might have destroyed at that moment too?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop and Start conversation in a same frame

Post by Tony Li »

When you stop a conversation, it gives all active sequencer commands one frame to finish. So waiting 1 frame should be acceptable.

I made this simplified test scene in Unity 2020.1:

DS_TestAmberAlert_2020-11-23.unitypackage

Please compare it to your scene. It might help you find what is different that is preventing your scene from working the way you want.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Stop and Start conversation in a same frame

Post by fkkcloud »

Okay, it was because I had DialogueActor component for SMS (override Dialogue UI) object within the regular one that has its own DialogueActor component for default Dialogue UI.

For instance, the prefab of the actor character is like below in the hierarchy.

Code: Select all

gameObject ([b]DialogueActor [/b]- actor = "Char_default")
----
---------gameObject ([b]DialogueActor [/b]- actor = "Char_SMS", Override Dialgoue UI)
If I remove the override DialogueActor gameObject right before going back to the default one, then it works.

Any suggestion so I can keep both DialogueActor in a single prefab?

edit: also, with DialogueManager's Debug Info, the speaker/conversant of the conversation that needs to trigger default UI is "correct" in the default Dialogue UI conversation.
It is using Char_default rather than Chat_SMS. but somehow, since the override dialogue UI component within the default, has been activated, it is using the override dialogue UI.
Only after once it is "used" - it does not do that for the first time.
For instance, if I just start conversation with Char_default for the first time, it works.
Only after I start a conversation with Char_SMS at least one time, it override the conversation with Char_default's conversation.

For a solution, I can detach the Char_SMS DialogueActor gameObject from Char_default DialogueActor gameObject so they are 2 separate prefab - which works perfectly. - maybe it is better like this anyway.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop and Start conversation in a same frame

Post by Tony Li »

Yes, it's better to keep them separate. You can still keep them in the same prefab if the Dialogue Actors are on two separate children and not nested in each other. Example:

Code: Select all

- Main GameObject
--- Child 1 (Dialogue Actor: "Char_default")
------- Child 1's children...
--- Child 2 (Dialogue Actor: "Char_SMS")
------- Child 2's children...
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Stop and Start conversation in a same frame

Post by fkkcloud »

works great- thank you
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Stop and Start conversation in a same frame

Post by Tony Li »

Glad to help!
Post Reply