Have dialogue restart in specific scenarios

Announcements, support questions, and discussion for the Dialogue System.
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Have dialogue restart in specific scenarios

Post by soniclinkerman »

In my game, the player is able to pause during dialogue. They have the option to go back to the main menu as well, but when you play again, the dialogue that was in process is still visible. Is there a way to RESTART that specific dialogue once I go back to that area?

So say I go through all Level 1 dialogue. I head over to level 2, but decide to just quit the game mid dialogue. How can I reset it so when thee player reaches that level again, it will start from the beginning?
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Have dialogue restart in specific scenarios

Post by Tony Li »

Hi,

If I understand correctly, would it work to:

1. Stop the current conversation when changing scenes, and
2. Don't save the current conversation state in saved games?

If so, then:

1. Add a short script like the one below to your Dialogue Manager.
2. Don't add a ConversationStateSaver to your game.
StopConversationOnSceneChange.cs (1)

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class StopConversationOnSceneChange : MonoBehaviour
{
    void Awake() 
    { 
        PixelCrushers.SaveSystem.sceneLoaded += (sceneName, sceneIndex) => { DialogueManager.StopConversation(); };
    }
}
(Fixed typo.)
StopConversationOnSceneChange.cs (2)

Code: Select all

using UnityEngine;
using UnityEngine.SceneManagement;
using PixelCrushers.DialogueSystem;

public class StopConversationOnSceneChange : MonoBehaviour
{
    void Awake()
    {
        SceneManager.sceneLoaded += (scene, mode) => { DialogueManager.StopConversation(); };
    }
}
(Added. Handles cases when not using save system.)
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

For some reason, I'm getting errors when I put this in a script I made
Attachments
Error.png
Error.png (130.41 KiB) Viewed 530 times
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

Also, just to clarify:

There might be a situation where the player pauses the game during a dialogue session. There's also a possibility they will QUIT and return back to the menu screen.

What should happen is, if they fail to complete that level, that specific dialogue should restart when they return. It would be as if they NEVER reached that conversation to begin with
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Have dialogue restart in specific scenarios

Post by Tony Li »

Hi,

I fixed a typo in my post above. I also added a variation that handles the case if you're not changing scenes using the save system. (However, in general, if you're using the save system, you should change scenes using the save system.)

There are a few more details that we may need to iron out. For example, if you're using a variable like in How To: Run a Conversation Only Once, you'll want to set that variable at the end of the conversation or whatever point in the conversation is deep enough to register as having reached/completed that conversation.
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

Hey Tony,

Yes, I plan for all these conversations to happen only once. What I did is use a boolean value to determine whether or not I've reached a point in the conversation that it never needs to appear again
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

The only issue I see now is this:
The player should be able to continue dialogue by either pressing "Z" or "Enter". SO I just added t2 "UI BUTTON KEY TRIGGER" scripts to the continue Button.


Furthermore, when the player presses "P" to pause, they can either press "Z" or "Enter" to exit or resume the game. How can I set it so pressing the "Enter" button doesn't activate the dialogue on resume. It doesn't do that when I press "Z", but does when I press "Enter"
User avatar
Tony Li
Posts: 22047
Joined: Thu Jul 18, 2013 1:27 pm

Re: Have dialogue restart in specific scenarios

Post by Tony Li »

Hi,

See: How To: Pause Dialogue In Pause Menu

The operative line is:

Code: Select all

PixelCrushers.UIButtonKeyTrigger.monitorInput = false;
but you'll probably want to use the entire code in that post.
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

The issue is a bit different...

Whenever I push the "Z" button during dialogue and the typewriter effect is happening, I'm able to press "Return" and it suddenly starts taking the "return" button, but I turned off that script JUST to test things. I even removed that extra button trigger component, but it's still taking "Return" as a way to progress dialogue.

Keep in mind, this issue ONLY happens when I do the following.

-Have dialogue typewriter effect in progress by pressing Z
-Immediately press return in the process of the effect

Then suddenly, it takes the value of return


NOTE: When I say return, I mean Enter. I'm using mac
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Have dialogue restart in specific scenarios

Post by soniclinkerman »

UPDATE

It seems if I untick "Simulate Button Click" in the UI Button Trigger, it works. I'm not too sure why that is, but it does
Post Reply