Page 1 of 1
How to Start conversation by script
Posted: Sun Aug 19, 2018 4:43 am
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?
Re: How to Start conversation by script
Posted: Sun Aug 19, 2018 6:52 am
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
)
Re: How to Start conversation by script
Posted: Sun Aug 19, 2018 6:57 am
by fanaei
Again Found the solution!
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.
Re: How to Start conversation by script
Posted: Sun Aug 19, 2018 10:11 am
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();
Re: How to Start conversation by script
Posted: Fri Dec 24, 2021 5:12 pm
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!
Re: How to Start conversation by script
Posted: Fri Dec 24, 2021 8:05 pm
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.