Getting Conversation End in Code
Getting Conversation End in Code
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.
Please answer in simple terms, I'm still new to coding. Thank you in advance.
Re: Getting Conversation End in Code
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":
To set finishedTalking to true when a conversation ends, add an OnConversationEnd method:
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.
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;
}
Code: Select all
public class MyScript : MonoBehaviour
{
bool finishedTalking;
void OnConversationEnd(Transform actor)
{
finishedTalking = true;
}
}
Re: Getting Conversation End in Code
Thank you! It's working now
Re: Getting Conversation End in Code
Happy to help!
Re: Getting Conversation End in Code
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?
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?
Re: Getting Conversation End in Code
I'm not getting any of the events as an option.
is not working. Looks similar to the manual page. Am I doing something wrong?
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?
Re: Getting Conversation End in Code
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.
Re: Getting Conversation End in Code
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.
Re: Getting Conversation End in Code
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.
Re: Getting Conversation End in Code
sorry for the crappy image. My website host is of course down for maintenance when I actually need it.