Get speaker gameobject in custom method in script field

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Get speaker gameobject in custom method in script field

Post by jjpixelc »

Hi

I'm looking for a way to get a reference to the speaker and listener game objects from a custom method in the script field of a conversation node.

When I use DialogueManager.CurrentConversationState I get the speaker/listener from the prior node, not the current node in (the node where I have placed my custom method in the script field). As I understand this is because the script field is executed before the dialogue entry is actually created.

What I am trying to do is set a variable on a script on the speaker gameobject. This variable will be used by a method in OnConversationLine event, which will determine the look of the speech bubble used for the subtitle.
My goal is to make it possible for the user to set the speechbubble version just by writing a quick order in the script field of the dialogue node.

Fx. putting Think() in a dialogue node's script field, will make the bubble for this subtitle show as a think-bubble instead of a normal talk-bubble.

I've got everything working, except getting that reference to the speaker gameobject right.

EDIT:
I know I could do this with SendMessage(think, , speaker/listener), but I was hoping to be able to make the command even more compact than that (user request).
User avatar
Tony Li
Posts: 22134
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get speaker gameobject in custom method in script field

Post by Tony Li »

If you're going to be doing this in a lot of dialogue entries, here's another approach:

1. Add a custom field to your dialogue entry template, such as "Bubble Style". You could even make it a custom field type that uses a nice dropdown menu.

2. Add a script with an OnConversationLine(Subtitle) method to your Dialogue Manager. In this method, check the Bubble Style field:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    string bubbleStyle = Field.LookupValue(Subtitle.dialogueEntry.fields, "Bubble Style");
    // code here to set the bubble style.
}
Post Reply