Trigger Specific Dialogue From Script?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Trigger Specific Dialogue From Script?

Post by PayasoPrince »

Hello,

I reviewed the tutorial videos and wasn't able to find this.

I want to trigger a specific dialogue from a usable when a specific method is called on my player.

For example:

My player with a ProximitySelector is in range of a usable GameObject.
My player then calls the method:

Code: Select all

private void GetReactionFromNPC:
{
        ProximitySelector.CurrentUsable." Start a specific dialogue now"
}
How can I accomplish this? :?:
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Specific Dialogue From Script?

Post by Tony Li »

Assuming I understand you correctly, I can suggest two ways to do that:

1. Put a Dialogue Actor on each NPC. Name each reaction conversation according to the Dialogue Actor's name plus " Reaction". For example, if the NPC is "Adam", then the conversation would be "Adam Reaction". Start it like this:

Code: Select all

string title = DialogueActor.GetActorName(ProximitySelector.CurrentUsable.transform) + " Reaction";
DialogueManager.StartConversation(title, this.transform, ProximitySelector.CurrentUsable.transform);

2. Or define a Boolean variable "Reaction" in your dialogue database. Add two Dialogue System Trigger components to the NPC. Configure the first one to start the NPC's normal conversation (if any). Set its Conditions > Lua Conditions to: Variable["Reaction"] ~= true. Configure the second Dialogue System Trigger to start the NPC's reaction conversation and run Lua code to set Reaction false. Set its Conditions > Lua Conditions to: Variable["Reaction"] == true. Start it like this:

Code: Select all

DialogueLua.SetVariable("Reaction", true);
ProximitySelector.UseCurrentSelection();
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Trigger Specific Dialogue From Script?

Post by PayasoPrince »

Thanks, Tony!

I went with the first way you mentioned and it seems to be working. The only problem is, it's not applying the "Cinemachine Camera Priority On Dialogue Event" Virtual Camera that I have on the actor. :?
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Trigger Specific Dialogue From Script?

Post by PayasoPrince »

More specifically, it's using the vcam that is on the Player. However, I need it to use the NPC's vcam.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Specific Dialogue From Script?

Post by Tony Li »

Hi,

Make sure the correct GameObjects are being used for the characters. For example, if in the Dialogue Editor you've set the conversation's Actor to be the Player and the Conversant to be the NPC, then make sure to pass the player transform as the second parameter to DialogueManager.StartConversation and pass the NPC transform as the third parameter.

Both GameObjects will receive the dialogue event. If you want the NPC's vcam to take priority, set its Cinemachine Camera Priority On Dialogue Event priority to a higher value.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Trigger Specific Dialogue From Script?

Post by PayasoPrince »

Oh, goodness. The issue was the third parameter. I was not passing the usables transform :oops:.

It's working wonderfully now, thanks!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger Specific Dialogue From Script?

Post by Tony Li »

Glad to help! :-)
Post Reply