Trigger dialogue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jrose1184
Posts: 69
Joined: Mon Jan 22, 2024 2:35 pm

Trigger dialogue

Post by jrose1184 »

Hi,

So I have a battle system and I have a npc that I want to talk to me at random parts of the battle. I want to trigger a dialogue and point the camera at him when he says somthing. So if I create a tree of different dialogues. How do I trigger this event though script and what components would the npc needs. Thanks
User avatar
Tony Li
Posts: 23259
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger dialogue

Post by Tony Li »

Hi,

To start a conversation from C#, use DialogueManager.StartConversation(). Example:

Code: Select all

DialogueManager.StartConversation("Combat Remarks", player.transform, npc.transform);
In the conversation's first dialogue entry node, you can use a Sequence such as this one to point the camera at the NPC, assuming the node is assigned to the NPC:

Code: Select all

{{default}};
Camera(Closeup)
To randomize it, you should set up the conversation like this:

combatRemarks.png
combatRemarks.png (26.94 KiB) Viewed 4370 times

Alternatively, you can use barks.
jrose1184
Posts: 69
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trigger dialogue

Post by jrose1184 »

Hi Thanks.

I think im doing somthing wrong.

So i added a Dialogue Actor to my Npc and assigned it's Actor.

Then in my converstations i copied your tree but on the first node i add a condition
Variable["LemonBattleCam"] == true - this is my empty gameobject that will be my camera.

then underneath that i assigned another 3 nodes and set 3 conditions to each one i.e
Variable["Intro"] == true
Variable["Block"] == true
Variable["WrongAttack"] == true

Then in my code i add
DialogueLua.SetVariable("LemonBattleCam", true);

but it does not work.

If i remove that condition on the parent node and use
DialogueManager.StartConversation("Battle Demo", player.transform, lemon.transform);

that does opens the converstation window but its blank. as im not using that bool.

It also does not point the camera, i alrready have a few cameras set up in my scene using cinemachine and in script im changing all the cameras prority to 10 and the active one to 100, So i need to override the 100 with this.

again im trying to set a bool to true to trigger that converstation i.e

DialogueLua.SetVariable("Intro", true);
jrose1184
Posts: 69
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trigger dialogue

Post by jrose1184 »

I managed to fix the camera with Cinemachine Priority On Dialogue Event
Just cant get the bools to work in c#
User avatar
Tony Li
Posts: 23259
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger dialogue

Post by Tony Li »

Hi,

This example may be helpful: How To: Run a Conversation Only Once. It's not exactly what you're doing, but it explains how to check a DS variable in a conversation, and it has screenshots.

See also the Logging & Debugging tutorial video. It explains how to turn on debug logging to see what the Dialogue System is doing under the hood -- when it's setting and checking variables, when it's starting conversations, etc.
jrose1184
Posts: 69
Joined: Mon Jan 22, 2024 2:35 pm

Re: Trigger dialogue

Post by jrose1184 »

Thanks i went with this and it worked


DialogueLua.SetVariable("Intro", false);

bool isTrue = DialogueLua.GetVariable("Intro").AsBool;
Debug.Log($"Intro Variable Value Before Starting: {isTrue}");

DialogueManager.StartConversation("Battle Demo");
Post Reply