Page 1 of 2
Getting Conversation End in Code
Posted: Sat Oct 27, 2018 5:41 pm
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.
Re: Getting Conversation End in Code
Posted: Sat Oct 27, 2018 6:27 pm
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.
Re: Getting Conversation End in Code
Posted: Sat Oct 27, 2018 7:31 pm
by willij
Thank you! It's working now
Re: Getting Conversation End in Code
Posted: Sat Oct 27, 2018 9:21 pm
by Tony Li
Happy to help!
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 12:39 pm
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?
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 1:11 pm
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?
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 1:45 pm
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.
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 1:50 pm
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.
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 2:12 pm
by nivlekius
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
Re: Getting Conversation End in Code
Posted: Wed Mar 13, 2019 2:17 pm
by nivlekius
sorry for the crappy image. My website host is of course down for maintenance when I actually need it.