Calling a custom unity function after the end of a dialogue

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21680
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling a custom unity function after the end of a dialogue

Post by Tony Li »

Glad to help! Thanks for your patience and for not reaching through the Internet tubes to strangle me for my habit of replying with great walls of text. ;-)
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Calling a custom unity function after the end of a dialogue

Post by simplepleasuresdxy »

Okay, so new question sir.

How do I invoke code at the end of certain dialogue. I know that this one was about conversation end or start, but sequencer command works for this?

I'm thinking that I could invoke a dialogue that asks if the player wants to move to a location after clicking on the trigger and when they hit no, it doesn't do anything. When they hit yes, they move to another scene or at least they invoke code that plays animation and moves them to another scene.
User avatar
Tony Li
Posts: 21680
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling a custom unity function after the end of a dialogue

Post by Tony Li »

Hi,

If it's okay to run that function while the conversation is technically still active but at the end, add an empty node to the end. Put your commands in the Script, Sequence, and/or OnExecute() Event sections. If you use the Sequence field, put "required" in front of your commands, and also include "Continue()" such as:

Code: Select all

required LoadLevel(Next Scene);
Continue()
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Calling a custom unity function after the end of a dialogue

Post by simplepleasuresdxy »

Im not sure if i follow. I understand the empty node part but everything else seems a bit above what i understand.

To be honest the scene to scene transition code itself is a bit beyond me so i only really know how to do it one way. What does your thing suggest?
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Calling a custom unity function after the end of a dialogue

Post by simplepleasuresdxy »

Hi tony,Im still having questions about this. I already have a script but i still dont know how to call it with a dialogue sequencer. I dont want to use the dialogue sequencer to activate the scene change, i want the script to do it, which you might have been confused by.

Is there anyway c# code can be called with a sequencer or a dialogue system trigger option im not aware of?
User avatar
Tony Li
Posts: 21680
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling a custom unity function after the end of a dialogue

Post by Tony Li »

simplepleasuresdxy wrote: Thu Aug 10, 2023 12:08 pmIs there anyway c# code can be called with a sequencer or a dialogue system trigger option im not aware of?
Yes. If your C# code is in method in a script, and that script is on a uniquely-named GameObject, you can use the SendMessage() sequencer command. For example, say your script is named MyAwesomeSceneChanger, and it has a method named ChangeScene("sceneName"), like this:

Code: Select all

public class MyAwesomeSceneChanger : MonoBehaviour
{
    public void ChangeScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }
}
Then say you've put this script on a GameObject named "MySceneChanger". Then you could use it to change to a scene named "Moon Lake" using this sequencer command:

Code: Select all

SendMessage(ChangeScene, Moon Lake, MySceneChanger)
If you want to put that in the last node of a conversation and have it automatically end the conversation, too, the whole Sequence would be:

Code: Select all

required SendMessage(ChangeScene, Moon Lake, MySceneChanger);
Continue()
Alternatively, you could write a custom sequencer command. They're not too hard to write. Here's another example that finds the MyAwesomeSceneChanger script no matter what GameObject it's on:

Code: Select all

using UnityEngine;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandChangeScene : SequencerCommand
    {
        var sceneChanger = GameObject.FindFirstObjectByType<MyAwesomeSceneChanger>();
        if (sceneChanger == null) Debug.LogError("Can't find MyAwesomeSceneChanger");
        else sceneChanger.ChangeScene(GetParameter(0));
        Stop();
    }
}
To use this in a sequence:

Code: Select all

required ChangeScene(Moon Lake;
Continue()
simplepleasuresdxy
Posts: 73
Joined: Tue Jul 25, 2023 1:34 am

Re: Calling a custom unity function after the end of a dialogue

Post by simplepleasuresdxy »

Okay. I see. Can the send message sequence change a c# boolean from false to true or would i have to make a script to change things? I have a boolean in a data container from scene to scene and i could create a script that when activated, turns that boolean to true, but now im wondering of send message can directly affect the boolean.
User avatar
Tony Li
Posts: 21680
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling a custom unity function after the end of a dialogue

Post by Tony Li »

No, the SendMessage can pass a string parameter or no parameter, but that's it. Here's an example of passing a string parameter:

Code: Select all

SendMessage(ChangeScene, Moon Lake, MySceneChanger);
Here's an example of no parameter:

Code: Select all

SendMessage(OpenDoor, , Front Door)
Post Reply