Page 1 of 1

Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 8:36 pm
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.

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 8:50 pm
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.

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:24 pm
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)"??

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:26 pm
by Tony Li
Yes. Or you could call your custom C# code in a custom sequencer command. (tutorial)

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:42 pm
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?

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:45 pm
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.

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:50 pm
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?

Re: Useful variable to use/animate mouth?

Posted: Wed Oct 07, 2020 9:58 pm
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.