Page 1 of 1

Get speaker gameobject in custom method in script field

Posted: Wed Mar 15, 2023 9:06 am
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).

Re: Get speaker gameobject in custom method in script field

Posted: Wed Mar 15, 2023 10:44 am
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.
}