Page 1 of 1

OnConversationEnd Problem

Posted: Sat Aug 19, 2017 1:09 pm
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.

Re: OnConversationEnd Problem

Posted: Sat Aug 19, 2017 2:18 pm
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;
}

Re: OnConversationEnd Problem

Posted: Sun Aug 20, 2017 6:59 am
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.

Re: OnConversationEnd Problem

Posted: Sun Aug 20, 2017 8:24 am
by Tony Li
Glad to help!