Useful variable to use/animate mouth?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Useful variable to use/animate mouth?

Post by fkkcloud »

Hi,

I have a mouth talk animation for my character. I want to use it as long as the voice actor line is playing. (also stop it when player just spam on "Continue" button as well).

What is good variable that I can reference to?
I am using a custom Lua script to start/stop mouth animation right now.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Useful variable to use/animate mouth?

Post by Tony Li »

Hi,

Use sequences. This is a very common thing to use sequences for.

Let's say the speaker has an Animator component with two states: Talk (mouth talking) and Idle (mouth closed). Set the Dialogue Manager's Default Sequence to:

Code: Select all

AnimatorPlay(Talk);
required AnimatorPlay(Idle)@Message(Typed)
The first line plays the "Talk" state on the speaker's Animator.

The second line:
  • Waits until the sequencer receives the sequencer message "Typed". The Dialogue System's typewriter effects send this sequencer message when they finish typing.
  • When it receives the sequencer message, it plays the "Idle" animation.
  • The 'required' keyword guarantees that the sequence plays this command even if the player uses the continue button to skip ahead.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Useful variable to use/animate mouth?

Post by fkkcloud »

Great-

I have to probably use Lua Script though since my facial animation is a custom thing so I will call a function from C# that is linked to Lua.

Would Script in each node would work with "@Message(Typed)"??
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Useful variable to use/animate mouth?

Post by Tony Li »

Yes. Or you could call your custom C# code in a custom sequencer command. (tutorial)
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Useful variable to use/animate mouth?

Post by fkkcloud »

Great.

So I created 2 C# files like below

Code: Select all

public class SequencerCommandStartTalkAnimation : SequencerCommand
    {

        public void Awake()
        {
            Debug.Log(speaker.gameObject.name + " started talking..");
            Stop();
        }
     }
     
In each dialogue node I have below..

Code: Select all

AudioWait(VA/Yuna_train_v02/What_should_my_next_song_v02);
AnimatorTrigger(Idle);
{{default}};
and in the "default sequence" command

Code: Select all

StartTalkAnimation();
required StopTalkAnimation()@Message(Typed);
Delay({{end}});
It seems to be working but let me know if this is the right way to do it.
Any possible way to match the typed to the audio file length?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Useful variable to use/animate mouth?

Post by Tony Li »

Hi,

Yes, that looks fine.

Eventually you may want to use entrytags. Then you can leave the dialogue node's Sequence field blank, and set the Default Sequence to:

Code: Select all

AudioWait(entrytag);
StartTalkAnimation();
required StopTalkAnimation()@Message(Typed);
Delay({{end}});
Each dialogue node will automatically replace the keyword 'entrytag' with the node's entrytag value.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Useful variable to use/animate mouth?

Post by fkkcloud »

Yup, Im planning to do that once my structure is in good state. I guess its almost there (thanks to your quick responses :lol: )

One thing though..
I ended up having these in Script section of each node:

Code: Select all

SetFacialEmotion("Wha");
PlayEmote("Exclamation")
which is fine but I'm afraid of possible type errors. Is there any way to setup a enum here or possible extend the each node inspector with my own stuff? is there any template for it as well?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Useful variable to use/animate mouth?

Post by Tony Li »

There's no good way to do that. But you can define separate functions such as:

SetFacialEmotion_Wha()
PlayEmote_Exclamation()
etc.

Then add them to a CustomLuaFunctionInfo asset so you can select them from a dropdown menu instead of typing them.
Post Reply