Getting Conversation End in Code

Announcements, support questions, and discussion for the Dialogue System.
willij
Posts: 15
Joined: Sat Oct 27, 2018 5:35 pm

Getting Conversation End in Code

Post by willij »

I'm using a script to trigger conversations through code but I also want to change a variable through code when the conversation ends. I'm not sure how to do this. How can I check for the conversation end? I would rather not do this in update, is there a event I can have my script listen for? But I only want this script to run for the script that triggered the conversation in the first place.

Please answer in simple terms, I'm still new to coding. Thank you in advance.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting Conversation End in Code

Post by Tony Li »

Hi,

There are two ways. First, you can add a script with a method named OnConversationEnd to the Dialogue Manager or either of the primary participants. This is a list of the special methods you can add: Script Messages.

For example, let's say you've added a script to the Dialogue Manager that has a bool variable named "finishedTalking":

Code: Select all

public class MyScript : MonoBehaviour
{
    bool finishedTalking;
}
To set finishedTalking to true when a conversation ends, add an OnConversationEnd method:

Code: Select all

public class MyScript : MonoBehaviour
{
    bool finishedTalking;
    
    void OnConversationEnd(Transform actor)
    {
        finishedTalking = true;
    }
}
Another way to set the variable is to add a Dialogue System Events component to the Dialogue Manager or one of the primary participants. This component has UnityEvents that work similarly to a UI Button's OnClick() event. You can hook up the OnConversationEnd() event to change a variable in your script or call another method in your script. This way you don't need to write any code at all.
willij
Posts: 15
Joined: Sat Oct 27, 2018 5:35 pm

Re: Getting Conversation End in Code

Post by willij »

Thank you! It's working now :D
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting Conversation End in Code

Post by Tony Li »

Happy to help!
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Getting Conversation End in Code

Post by nivlekius »

Hi,
I'm sorry to necro this post. I never really understood what was wrong with doing that but I guess people don't like it. But my issue goes along with this so I wanted to put it here. When I use Pixelcrushers.DialogueSystem I'm not getting OnConversationEnd as an option. Should I?
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Getting Conversation End in Code

Post by nivlekius »

I'm not getting any of the events as an option.

Code: Select all

using PixelCrushers.DialogueSystem;

public class Dialogue_Events : MonoBehaviour {

    [HideInInspector]
    public bool npcTalking;
    [HideInInspector]
    public Transform actor;

	void Start ()
    {
		
	}
	
	void Update ()
    {
		
	}

    public void OnConversationEnd(Transform actor)
    {
        Debug.Log("Conversation over");
    }

is not working. Looks similar to the manual page. Am I doing something wrong?
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting Conversation End in Code

Post by Tony Li »

Is your Dialogue_Events script on the Dialogue Manager or one of the conversation participants (e.g., assigned to the Dialogue System Trigger's Conversation Actor or Conversation Conversant field)? The Script Messages section has a table that explains which GameObjects will receive messages such as OnConversationEnd.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Getting Conversation End in Code

Post by nivlekius »

Yeah, I've had that page opened in several tabs. Looked over it quite a few times and don't understand why I'm unable to get the On-whatever to show up as options. If I'm "using DialogueSystem it should show me the options and allow me to write the code regardless of when it is yet on an object shouldn't it? It is on an actor by the way.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Getting Conversation End in Code

Post by nivlekius »

Image

this is what I mean. Shouldn't I see OnConversationEnd in the dropdown and then be able to write my code? Even if not, the script attached to the actor isn't working. Just wondering what I'm missing.

Edit - there, better image
Last edited by nivlekius on Wed Mar 13, 2019 2:30 pm, edited 1 time in total.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Getting Conversation End in Code

Post by nivlekius »

sorry for the crappy image. My website host is of course down for maintenance when I actually need it.
Post Reply