OnConversationEnd Problem

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

OnConversationEnd Problem

Post by Barto1983 »

Hallo friends,

i have a little problem.

I have 3 Scenes + 1 Dialogue Manager Database + 2 Conversations.

now my Problem:

Script Scene01.cs has following function

Code: Select all

void OnConversationEnd(Transform actor)
    {
        SceneManager.LoadScene("Scene02",LoadSceneMode.Single);  
    }
I add the script to the Dialogue Manager in Scene01

Script Scene02.cs has following function

Code: Select all

void OnConversationEnd(Transform actor)
    {
        SceneManager.LoadScene("Scene03",LoadSceneMode.Single);  
    }
I add the script to the Dialogue Manager in Scene02

Example:

Start New Game -> Scene01 is loading -> Conversation01 is loading -> Conversation01 finish -> trigger OnConversationEnd() -> Perfect Scene02 is loading

Scene02 is loaded -> Conversation02 is loading -> Conversation02 finish -> trigger OnConversationEnd() -> ERROR Scene02 is loading.


Question how can i override the OnConversationEnd() function.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnConversationEnd Problem

Post by Tony Li »

Hi!

Since the Dialogue Manager survives scene changes, any scripts on it will also survive scene changes.

Here are some options:

1. Put your scripts on a different GameObject, not the Dialogue Manager. This GameObject must be the actor or conversant of the conversation (i.e., assigned to the Conversation Trigger's Actor or Conversant field).

2. Or, if the game will not return to Scene01, you can add this line to Scene01.cs:

Code: Select all

void OnConversationEnd(Transform actor)
{
    SceneManager.LoadScene("Scene02",LoadSceneMode.Single);  
    Destroy(this); // ADD THIS LINE. REMOVES THIS SCRIPT AFTER LOADING SCENE02.
}
3. Or, you can combine your scripts:
SceneXX.cs

Code: Select all

void OnConversationEnd(Transform actor)
{
    switch (SceneManager.GetActiveScene().name)
    {
        case "Scene01":
            SceneManager.LoadScene("Scene02",LoadSceneMode.Single);  
            break;
        case "Scene02":
            SceneManager.LoadScene("Scene03",LoadSceneMode.Single);  
            break;
}
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: OnConversationEnd Problem

Post by Barto1983 »

Hello,

Thank you for your help.

I am shocked that I have not come to it myself.

As always, perfect support.

Thanks again.
User avatar
Tony Li
Posts: 21722
Joined: Thu Jul 18, 2013 1:27 pm

Re: OnConversationEnd Problem

Post by Tony Li »

Glad to help!
Post Reply