How to Start conversation by script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

How to Start conversation by script

Post by fanaei »

Hi. I don't want to start conversation by default triggers in Dialogue system trigger.
I searched everywhere but I couldn't find a way for it.
Is there any code for starting the conversation from inside my scripts?
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: How to Start conversation by script

Post by fanaei »

Ok, finally I found this. But how can I get the conversation title from Dialogue system trigger component?

PixelCrushers.DialogueSystem.DialogueManager.StartConversation ( string title,
Transform actor,
Transform conversant,
int initialDialogueEntryID
)
fanaei
Posts: 73
Joined: Wed Aug 15, 2018 10:38 am

Re: How to Start conversation by script

Post by fanaei »

Again Found the solution! :D
I hope I'm doing it right..
DialogueManager.StartConversation(TargetObject.GetComponent<DialogueSystemTrigger>().conversation.ToString(), TargetObject.transform);

But as always faced a new problem!
Now the Dialogue system events, doesn't work and my codes for OnConversationStart or End, are useless.
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to Start conversation by script

Post by Tony Li »

Hi,

The Dialogue Manager always receives Dialogue System event messages. If you want the actor or conversant to receive Dialogue System event messages, you must specify the actor and conversant in DialogueManager.StartConversation():

Code: Select all

var conversation = TargetObject.GetComponent<DialogueSystemTrigger>().conversation;
var actor = TargetObject;
var conversant = /* some other GameObject? */
DialogueManager.StartConversation(conversation, actor, conversant);
If you want, you can also add these fields directly to your own script and bypass Dialogue System Trigger:

Code: Select all

[ConversationPopup] public string conversation;
 public Transform actor;
 public Transform conversant;
 ...
 void StartMyConversation()
 {
     DialogueManager.StartConversation(conversation, actor, conversant);
 }
Or you can set up the Dialogue System Trigger with the correct actor and conversant, set its Trigger to OnUse, and call OnUse() manually:

Code: Select all

TargetObject.GetComponent<DialogueSystemTrigger>().OnUse();
HunterTom
Posts: 18
Joined: Fri Dec 24, 2021 4:58 pm

Re: How to Start conversation by script

Post by HunterTom »

Hi I have a follow up question.

What if my actor is talking to himself? Can I leave conversant as Null?

Also, how do I specify which to use in the following code?

var conversation = TargetObject.GetComponent<DialogueSystemTrigger>().conversation;

Thank you!
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to Start conversation by script

Post by Tony Li »

Hi,

Yes, you can leave the conversant as null.
HunterTom wrote: Fri Dec 24, 2021 5:12 pmAlso, how do I specify which to use in the following code?

var conversation = TargetObject.GetComponent<DialogueSystemTrigger>().conversation;
The previous poster already had a TargetObject value. I don't know what it was. But presumably it's an NPC or object that has a Dialogue System Trigger component.
Post Reply