Time custom script with sequence

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

Time custom script with sequence

Post by jjpixelc »

Hi

I am trying to achieve this:
Have a way to fire off a think-bubble above a given characters head with a comment during and after conversations.
I'm doing this by using Bark UI and a registered function that fires it off.
The function takes 3 parameters.

My problem is that since my registered function can only be activated from the script field, I cannot control the timing of it.
Which I want to. I want to be able to do 2 things:

Fire ThinkBubble above "speaker X" containing text "XXXXX" at "X" seconds after sequence end.
and
Fire ThinkBubble above "speaker X" containing text "XXXXX" at "X" seconds into sequence.

So, I want to be able to fire it both in the middle of a sequence and at the end of conversations/sequences.
I have everything working except the timing bit.

As I understand it, you cannot send messages between the sequence field and the script field - but I see no other way to achieve what I want.
I cannot run my function from the sequence field via sendmessage as I cannot make it work with only a single string parameter.
I cannot use a custom sequencer command as I need to reference objects and other functions outside the Dialogue Manager.
I cannot just use the script field as I see no way to time it precisely with the sequencer (Currently, I have a delay parameter in the function, but this is very awkward to use as I need to manually adjust and test it for every node I use it with).
User avatar
Tony Li
Posts: 22166
Joined: Thu Jul 18, 2013 1:27 pm

Re: Time custom script with sequence

Post by Tony Li »

Sequencer commands are a good way to go. Your custom sequencer command can reference two properties:
  • speaker: The GameObject that's speaking the line (usually the dialogue entry node's Actor). Or, in the case of a Dialogue System Trigger > Actions > Play Sequence, the GameObject that's assigned to the Play Sequence action.
  • listener: The GameObject that's being addressed (usually the dialogue entry node's Conversant).
You can also get any arbitrary GameObject by name using the SequencerCommand.GetSubject() method.

Because sequencer commands use a simplified syntax without "quotes" surrounding strings, it's not always possible to pass an arbitrary string as a parameter. However, you can set the string in the Script field.

For example, say that during a conversation you want to fire a ThinkBubble above the node's speaker, containing text "This works, right?" at the 3-second mark. So you set the Script and Sequence fields to:
  • Script: Variable["ThinkText"] = "This works, right?"
  • Sequence: {{default}}; ThinkBubble(speaker)@3
Then write a SequencerCommandThinkBubble script similar to this:
SequencerCommandThinkBubble.cs

Code: Select all

// (Omitted things like using statements for brevity.)
// Syntax: ThinkBubble(actor)
// - where actor is 'speaker', 'listener', or a GameObject name. Defaults to 'speaker' if omitted.

public class SequencerCommandThinkBubble : SequencerCommand
{
    void Awake()
    {
        Transform thinker = GetSubject(0, speaker); // First parameter is thinker name, or 'speaker' if omitted.
        string text = DialogueLua.GetVariable("ThinkText");
        DialogueManager.BarkString(thinker, text);
        Stop();
    }
}
---

Alternatively, you can set up the entire conversation using an interactive sequence editor such as Unity Timeline or SLATE. That's probably more hassle than you want, though.
jjpixelc
Posts: 44
Joined: Sun Mar 01, 2020 1:04 pm

Re: Time custom script with sequence

Post by jjpixelc »

Hi

That is a brilliantly simple and effective way to do this.
Setting the text as a variable in the script field and then firing from the sequencer, that is perfect.
A little embarrassed that I didn't think of this myself :-)
User avatar
Tony Li
Posts: 22166
Joined: Thu Jul 18, 2013 1:27 pm

Re: Time custom script with sequence

Post by Tony Li »

Glad to help!
Post Reply