Page 1 of 1

Action On Conversation End

Posted: Thu Jun 29, 2017 3:34 pm
by sdclark79
Hello all!

I am trying to learn how to execute functions on conversation end, but I am having some difficulties. I am starting the conversation with:

Code: Select all

DialogueManager.StartConversation ("New Conversation 2");
... inside of a coroutine attached to an NPC. When the conversation finishes, I'm trying to run a simple test:

Code: Select all

public void EndConversation(){
    Debug.Log("EndConversation() called");
}
I attached DialogueSystemEvents script to the NPC and added a new OnConversationEnd using EndConversation().

I also perused the Forum but wasn't sure how to get the OnConversationEnd(Transform object) to work.

Any help would be much appreciated.

Thanks!

Re: Action On Conversation End

Posted: Thu Jun 29, 2017 4:11 pm
by Tony Li
Hi,

The tables on this page explain which GameObjects receive events such as OnConversationStart and OnConversationEnd.

OnConversationEnd is sent to the Dialogue Manager GameObject and the conversation participants' GameObjects. You can specify the participant GameObjects in DialogueManager.StartConversation. For example:

Code: Select all

DialogueManager.StartConversation ("New Conversation 2", GameObject.FindWithTag("Player").transform, this.transform);
The OnConversationEnd event will be sent to the Dialogue Manager, the GameObject tagged "Player", and the GameObject running this script (i.e., your NPC).

If you don't specify participants, the Dialogue System will attempt to find a GameObject whose name matches the actor's name in the dialogue database. If you've added an Override Actor Name component to a GameObject, the Dialogue System will match the GameObject to the actor name.

If you temporarily set the Dialogue Manager's Debug Level to Info, it will log a lot of information to the Console window. You should be able to find a line like:

Code: Select all

Dialogue System: Starting conversation 'New Conversation 2' with actor=XXX and conversant=YYY.
where XXX and YYY are GameObjects in the scene.

Since you're already writing a script, I'd recommend using the OnConversationEnd(Transform) method so it's all in the script instead of also using a Dialogue System Events component. For example:

Code: Select all

public class YourNPCScript : MonoBehaviour {
    IEnumerator YourCoroutine() {
        DialogueManager.StartConversation ("New Conversation 2", GameObject.FindWithTag("Player").transform, this.transform);
    }

    void OnConversationEnd(Transform actor) {
        Debug.Log("THE CONVERSATION ENDED!!!");
    }
}

Re: Action On Conversation End

Posted: Thu Jun 29, 2017 5:02 pm
by sdclark79
Thank you for the great explanation! Hopefully someone else'll stumble across this, I was having a hard time understanding the specifics of the usage of StartConversation, and that was very detailed and awesome of you.

Here's the working debug, which I took your last advice and stuck it in the same script. Thanks again!

Code: Select all

IEnumerator MoveToPlayer(){
		//Track coroutine status
		isCoroutineActive = true;
		oneTime = true;

		yield return new WaitForSeconds (12f);
		
		//Set nav destination to entryway gate and wait for open
		unitNavMeshAgent.SetDestination (setGatePosition.transform.position);

		yield return new WaitForSeconds (13f);
		
		//Set walking speed and nav destination to Player
		unitNavMeshAgent.speed = 2f;
		unitNavMeshAgent.SetDestination (playerGO.transform.position);

		yield return new WaitForSeconds (4f);
		
		//Start conversation and end coroutine
		//Syntax:
		//StartConversation (string title, Transform actor, Transform conversant);
		DialogueManager.StartConversation ("New Conversation 2", playerGO.transform, this.transform);
		
		isCoroutineActive = false;

		yield return null;

	}

	void OnConversationEnd(Transform actor){

		Debug.Log ("Conversation Ended");

	}

Re: Action On Conversation End

Posted: Thu Jun 29, 2017 8:22 pm
by Tony Li
Happy to help! Thanks for sharing your debug code!